This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for getting the calling app's permission state for activities
This allows for apps that can already access the calling app identity that opens their activity, along with system browser, to check whenever a permission is granted, similar to the permission entry in activity section of AndroidManifest.xml.
- Loading branch information
Showing
5 changed files
with
117 additions
and
0 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
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
77 changes: 77 additions & 0 deletions
77
services/core/java/com/android/server/wm/WindowManagerHooks.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,77 @@ | ||
package com.android.server.wm; | ||
|
||
import android.annotation.NonNull; | ||
import android.annotation.Nullable; | ||
import android.app.ActivityThread; | ||
import android.content.Context; | ||
import android.content.pm.PackageManager; | ||
import android.content.pm.PackageManagerInternal; | ||
import android.ext.BrowserUtils; | ||
import android.os.Binder; | ||
import android.os.Build; | ||
import android.os.SystemProperties; | ||
import android.os.UserHandle; | ||
|
||
import com.android.internal.util.ArrayUtils; | ||
|
||
import com.android.server.LocalServices; | ||
import com.android.server.pm.permission.PermissionManagerServiceInternal; | ||
import com.android.server.pm.pkg.AndroidPackage; | ||
import com.android.server.pm.pkg.PackageStateInternal; | ||
|
||
class WindowManagerHooks { | ||
|
||
static boolean canAccessLaunchedFromPackagePermission() { | ||
final int callingUid = Binder.getCallingUid(); | ||
var pmi = LocalServices.getService(PackageManagerInternal.class); | ||
AndroidPackage callingPkg = pmi.getPackage(callingUid); | ||
if (callingPkg == null) { | ||
return false; | ||
} | ||
|
||
String callingPkgName = callingPkg.getPackageName(); | ||
if (canAccessForDebuggingPurposes(callingPkgName)) { | ||
return true; | ||
} | ||
|
||
Context ctx = ActivityThread.currentActivityThread().getSystemContext(); | ||
if (!BrowserUtils.isSystemBrowser(ctx, callingPkgName)) { | ||
return false; | ||
} | ||
|
||
PackageStateInternal callingPsi = pmi.getPackageStateInternal(callingPkg.getPackageName()); | ||
if (callingPsi == null) { | ||
return false; | ||
} | ||
|
||
return callingPsi.isSystem(); | ||
} | ||
|
||
static boolean canAccessForDebuggingPurposes(@NonNull String packageName) { | ||
if (!Build.isDebuggable()) { | ||
return false; | ||
} | ||
|
||
String testPkgs = SystemProperties.get("persist.launchedFromPackagePermission_test_pkgs"); | ||
return ArrayUtils.contains(testPkgs.split(","), packageName); | ||
} | ||
|
||
static int checkLaunchedFromPackagePermission(@Nullable ActivityRecord r, @NonNull String permission) { | ||
if (r == null) { | ||
return PackageManager.PERMISSION_DENIED; | ||
} | ||
|
||
String packageName = r.launchedFromPackage; | ||
final int userId = UserHandle.getUserId(r.launchedFromUid); | ||
var permService = LocalServices.getService(PermissionManagerServiceInternal.class); | ||
|
||
// Do not take into account of package visibility here. | ||
long token = Binder.clearCallingIdentity(); | ||
try { | ||
return permService.checkPermission(packageName, permission, userId); | ||
} finally { | ||
Binder.restoreCallingIdentity(token); | ||
} | ||
|
||
} | ||
} |