summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeter Visontay <pvisontay@google.com>2017-11-27 15:23:57 +0000
committerPeter Visontay <pvisontay@google.com>2018-01-08 11:25:17 +0000
commit285ea8f0b56a4b897ed79f10770e299329325f93 (patch)
treeb433cfc64647331f9acf920b8dd803a671f8ec20 /src
parent70d2145be5999bff22dc427ec86259bae9042f75 (diff)
downloadandroid_packages_apps_PackageInstaller-285ea8f0b56a4b897ed79f10770e299329325f93.tar.gz
android_packages_apps_PackageInstaller-285ea8f0b56a4b897ed79f10770e299329325f93.tar.bz2
android_packages_apps_PackageInstaller-285ea8f0b56a4b897ed79f10770e299329325f93.zip
Log an App Op when a package is requested to be deleted by a third party. (REQUEST_DELETE_PACKAGES)
Bug: 63907873 Test: manually with PackageInstaller.uninstall() and ACTION_UNINSTALL_PACKAGE (both with startActivity() and startActivityForResult()). Test: Ran GTS tests: GtsPackageInstallSessionTestCases, GtsExternalSourcesTestCases, GtsExternalSourcesNegativeTestCases Change-Id: I545a88eb50433a7d5ee96e71dfa853e93fb9372d
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/android/packageinstaller/UninstallerActivity.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/com/android/packageinstaller/UninstallerActivity.java b/src/com/android/packageinstaller/UninstallerActivity.java
index bbd0155c..1fc2b790 100755
--- a/src/com/android/packageinstaller/UninstallerActivity.java
+++ b/src/com/android/packageinstaller/UninstallerActivity.java
@@ -16,6 +16,8 @@
*/
package com.android.packageinstaller;
+import static android.app.AppOpsManager.MODE_ALLOWED;
+
import static com.android.packageinstaller.PackageUtil.getMaxTargetSdkVersionForUid;
import android.Manifest;
@@ -23,6 +25,7 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityThread;
import android.app.AppGlobals;
+import android.app.AppOpsManager;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
@@ -89,6 +92,25 @@ public class UninstallerActivity extends Activity {
try {
int callingUid = ActivityManager.getService().getLaunchedFromUid(getActivityToken());
+ String callingPackage = getPackageNameForUid(callingUid);
+ if (callingPackage == null) {
+ Log.e(TAG, "Package not found for originating uid " + callingUid);
+ setResult(Activity.RESULT_FIRST_USER);
+ finish();
+ return;
+ } else {
+ AppOpsManager appOpsManager = (AppOpsManager) getSystemService(
+ Context.APP_OPS_SERVICE);
+ if (appOpsManager.noteOpNoThrow(
+ AppOpsManager.OPSTR_REQUEST_DELETE_PACKAGES, callingUid, callingPackage)
+ != MODE_ALLOWED) {
+ Log.e(TAG, "Install from uid " + callingUid + " disallowed by AppOps");
+ setResult(Activity.RESULT_FIRST_USER);
+ finish();
+ return;
+ }
+ }
+
if (getMaxTargetSdkVersionForUid(this, callingUid)
>= Build.VERSION_CODES.P && AppGlobals.getPackageManager().checkUidPermission(
Manifest.permission.REQUEST_DELETE_PACKAGES, callingUid)
@@ -360,4 +382,12 @@ public class UninstallerActivity extends Activity {
}
}
}
+
+ private String getPackageNameForUid(int sourceUid) {
+ String[] packagesForUid = getPackageManager().getPackagesForUid(sourceUid);
+ if (packagesForUid == null) {
+ return null;
+ }
+ return packagesForUid[0];
+ }
}