-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support default impl for RemoteVerify
- Loading branch information
Showing
5 changed files
with
50 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
host/src/main/java/com/lzh/nonview/router/host/DefaultVerify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.lzh.nonview.router.host; | ||
|
||
import android.content.Context; | ||
import android.os.Binder; | ||
import android.util.Log; | ||
|
||
/** | ||
* <b>Default impl for {@link RemoteVerify}</b> | ||
* | ||
* <p>This class to ensure that the remote-client should have the same package name with service. | ||
*/ | ||
final class DefaultVerify implements RemoteVerify{ | ||
|
||
@Override | ||
public boolean verify(Context context) throws Exception { | ||
String packageName = context.getPackageName(); | ||
int uid = Binder.getCallingUid(); | ||
String[] packages = context.getPackageManager().getPackagesForUid(uid); | ||
if (packages == null) { | ||
packages = new String[0]; | ||
} | ||
for (String pack: packages) { | ||
if (packageName.equals(pack)) { | ||
return true; | ||
} | ||
} | ||
Log.e("DefaultVerify", String.format("The client with uid %s connected failed:", uid)); | ||
return false; | ||
} | ||
} |
11 changes: 5 additions & 6 deletions
11
host/src/main/java/com/lzh/nonview/router/host/RemoteVerify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package com.lzh.nonview.router.host; | ||
|
||
import android.app.Service; | ||
import android.os.Binder; | ||
import android.content.Context; | ||
|
||
/** | ||
* Provide an interface for security verification. | ||
*/ | ||
public interface RemoteVerify { | ||
/** | ||
* Verify the plug-in you are connecting to. | ||
* @param service The remote service. | ||
* @param binder The remote binder | ||
* Verify the client you are connecting to. | ||
* @param context The application context to provide managers. | ||
* @return returns true if safety | ||
* @throws Exception error occurs | ||
*/ | ||
boolean verify(Service service, Binder binder); | ||
boolean verify(Context context) throws Exception; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters