Compare commits
2 commits
6b18f2c355
...
684e5a0350
Author | SHA1 | Date | |
---|---|---|---|
684e5a0350 | |||
df70a6b57c |
1 changed files with 32 additions and 17 deletions
|
@ -18,6 +18,7 @@ import android.os.RemoteException;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -91,6 +92,8 @@ public class DummyActivity extends Activity {
|
||||||
private static final int REQUEST_PERMISSION_EXTERNAL_STORAGE= 2;
|
private static final int REQUEST_PERMISSION_EXTERNAL_STORAGE= 2;
|
||||||
private static final int REQUEST_PERMISSION_POST_NOTIFICATIONS = 3;
|
private static final int REQUEST_PERMISSION_POST_NOTIFICATIONS = 3;
|
||||||
|
|
||||||
|
private static boolean sHasRequestedPermission = false;
|
||||||
|
|
||||||
// A state variable to record the last time DummyActivity was informed that someone
|
// A state variable to record the last time DummyActivity was informed that someone
|
||||||
// in the same process needs to call an action without signature
|
// in the same process needs to call an action without signature
|
||||||
// Since they must be in the same process as DummyActivity, it will be totally fine
|
// Since they must be in the same process as DummyActivity, it will be totally fine
|
||||||
|
@ -133,16 +136,22 @@ public class DummyActivity extends Activity {
|
||||||
Utility.enforceUserRestrictions(this);
|
Utility.enforceUserRestrictions(this);
|
||||||
SettingsManager.getInstance().applyAll();
|
SettingsManager.getInstance().applyAll();
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
synchronized (DummyActivity.class) {
|
||||||
// We pretty much only send notifications to keep the process inside work profile alive
|
// Do not show permission dialog during finalization -- it will conflict with the provisioning UI
|
||||||
// as such, only request the notification permission from inside the profile
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && !sHasRequestedPermission
|
||||||
// This will ideally be shown and done when finalizing the profile (since it will go
|
&& !FINALIZE_PROVISION.equals(getIntent().getAction())) {
|
||||||
// through this activity)
|
// Avoid requesting permission multiple times in one session
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS)
|
// This also prevents multiple instances of DummyActivity from being blocked on each other
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
sHasRequestedPermission = true;
|
||||||
requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, REQUEST_PERMISSION_POST_NOTIFICATIONS);
|
// We pretty much only send notifications to keep the process inside work profile alive
|
||||||
// Continue once the request has been completed (see onRequestPermissionResult)
|
// as such, only request the notification permission from inside the profile
|
||||||
return;
|
// This will ideally be shown and done when the user sees the app list UI for the first time
|
||||||
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, REQUEST_PERMISSION_POST_NOTIFICATIONS);
|
||||||
|
// Continue once the request has been completed (see onRequestPermissionResult)
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,13 +257,19 @@ public class DummyActivity extends Activity {
|
||||||
|
|
||||||
private void actionFinalizeProvision() {
|
private void actionFinalizeProvision() {
|
||||||
if (mIsProfileOwner) {
|
if (mIsProfileOwner) {
|
||||||
// This is the action used by DeviceAdminReceiver to finalize the setup
|
// Only notify the main profile on pre-Oreo
|
||||||
// The work has been finished in onCreate(), now we just have to
|
// After Oreo, since we use the activity-based finalization flow,
|
||||||
// inform the main profile about this
|
// the setup wizard will wait until we finish finalization before returning
|
||||||
Intent intent = new Intent(FINALIZE_PROVISION);
|
// (Note: the actual finalization is done by common code in onCreate)
|
||||||
// We don't need signature for this intent
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
Utility.transferIntentToProfileUnsigned(this, intent);
|
// This is the action used by DeviceAdminReceiver to finalize the setup
|
||||||
startActivity(intent);
|
// The work has been finished in onCreate(), now we just have to
|
||||||
|
// inform the main profile about this
|
||||||
|
Intent intent = new Intent(FINALIZE_PROVISION);
|
||||||
|
// We don't need signature for this intent
|
||||||
|
Utility.transferIntentToProfileUnsigned(this, intent);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
// Set the flag telling MainActivity that we have now finished provisioning
|
// Set the flag telling MainActivity that we have now finished provisioning
|
||||||
|
|
Loading…
Add table
Reference in a new issue