Skip to content

Commit 4778e63

Browse files
committed
DevicePolicyGmsHooks: show toast if install fails
1 parent 2fea2c6 commit 4778e63

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyGmsHooks.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static android.app.AppOpsManager.MODE_ALLOWED;
44

55

6+
import android.annotation.SuppressLint;
67
import android.app.AppOpsManager;
78
import android.content.Context;
89
import android.content.pm.ApplicationInfo;
@@ -11,6 +12,7 @@
1112
import android.ext.PackageId;
1213
import android.os.RemoteException;
1314
import android.provider.Settings;
15+
import android.widget.Toast;
1416

1517
import com.android.server.utils.Slogf;
1618

@@ -61,14 +63,20 @@ public void maybeInstallPlay(int targetUserId, int callerUserId, String[] pkgNam
6163
}
6264

6365
if (shouldInstall) {
64-
installPlay(targetUserId, callerUserId);
66+
if (!installPlay(targetUserId, callerUserId)) {
67+
Toast.makeText(mContext.getApplicationContext(),
68+
"Failed to install Google Play in work profile despite requested by work profile App!",
69+
Toast.LENGTH_LONG
70+
).show();
71+
}
6572
}
6673
}
6774
/**
6875
* GrapheneOS Handler to install sandboxed play into managed user profile
6976
* in order to allow DPC apps that require play services to work normally
7077
*/
71-
private void installPlay(int targetUserId, int callerUserId) {
78+
@SuppressLint("MissingPermission")
79+
private boolean installPlay(int targetUserId, int callerUserId) {
7280
// TODO: possibly copy permissions from existing install in managing user?
7381
Slogf.i(LOG_TAG, "Installing play for user " + targetUserId);
7482

@@ -112,7 +120,7 @@ private void installPlay(int targetUserId, int callerUserId) {
112120
} else {
113121
// TODO: intent to app store to install play packages?
114122
Slogf.w(LOG_TAG, "Play Services not installed, yet requested for profile!");
115-
return;
123+
return false;
116124
}
117125

118126
/* Signature check. If play store was already installed into profile earlier,
@@ -130,8 +138,11 @@ but with untrusted signature (should not happen) then this will throw */
130138
PackageId.PLAY_STORE_NAME, /* flags= */ 0, targetUserId);
131139
mIAppOpsManager.setMode(AppOpsManager.OP_REQUEST_INSTALL_PACKAGES, storeUid,
132140
PackageId.PLAY_STORE_NAME, MODE_ALLOWED);
141+
142+
return true;
133143
} catch (RemoteException e) {
134144
// Does not happen, same process
145+
return false;
135146
}
136147
}
137148
}

0 commit comments

Comments
 (0)