Merge "Create emergency button in work profile unlaunchable app dialog"

This commit is contained in:
Oli Thompson
2023-01-12 16:05:30 +00:00
committed by Android (Google) Code Review
6 changed files with 132 additions and 50 deletions

View File

@@ -28,11 +28,13 @@ import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.os.UserManager;
import android.telecom.TelecomManager;
import android.util.Log;
import android.view.Window;
@@ -52,6 +54,7 @@ public class UnlaunchableAppActivity extends Activity
private int mUserId;
private int mReason;
private IntentSender mTarget;
private TelecomManager mTelecomManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -60,9 +63,11 @@ public class UnlaunchableAppActivity extends Activity
// TODO: Use AlertActivity so we don't need to hide title bar and create a dialog
requestWindowFeature(Window.FEATURE_NO_TITLE);
Intent intent = getIntent();
mTelecomManager = getSystemService(TelecomManager.class);
mReason = intent.getIntExtra(EXTRA_UNLAUNCHABLE_REASON, -1);
mUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
mTarget = intent.getParcelableExtra(Intent.EXTRA_INTENT, android.content.IntentSender.class);
mTarget = intent.getParcelableExtra(Intent.EXTRA_INTENT,
android.content.IntentSender.class);
if (mUserId == UserHandle.USER_NULL) {
Log.wtf(TAG, "Invalid user id: " + mUserId + ". Stopping.");
@@ -70,29 +75,40 @@ public class UnlaunchableAppActivity extends Activity
return;
}
String dialogTitle;
String dialogMessage = null;
if (mReason == UNLAUNCHABLE_REASON_QUIET_MODE) {
dialogTitle = getDialogTitle();
dialogMessage = getDialogMessage();
} else {
if (mReason != UNLAUNCHABLE_REASON_QUIET_MODE) {
Log.wtf(TAG, "Invalid unlaunchable type: " + mReason);
finish();
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(dialogTitle)
.setMessage(dialogMessage)
.setOnDismissListener(this);
if (mReason == UNLAUNCHABLE_REASON_QUIET_MODE) {
builder.setPositiveButton(R.string.work_mode_turn_on, this)
.setNegativeButton(R.string.cancel, null);
String targetPackageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
boolean showEmergencyCallButton =
(targetPackageName != null && targetPackageName.equals(
mTelecomManager.getDefaultDialerPackage(UserHandle.of(mUserId))));
final AlertDialog.Builder builder;
final String dialogMessage;
if (showEmergencyCallButton) {
builder = new AlertDialog.Builder(this, R.style.AlertDialogWithEmergencyButton);
dialogMessage = getDialogMessage(R.string.work_mode_dialer_off_message);
builder.setNeutralButton(R.string.work_mode_emergency_call_button, this);
} else {
builder.setPositiveButton(R.string.ok, null);
builder = new AlertDialog.Builder(this);
dialogMessage = getDialogMessage(R.string.work_mode_off_message);
}
builder.setTitle(getDialogTitle())
.setMessage(dialogMessage)
.setOnDismissListener(this)
.setPositiveButton(R.string.work_mode_turn_on, this)
.setNegativeButton(R.string.cancel, null);
final AlertDialog dialog = builder.create();
dialog.create();
if (showEmergencyCallButton) {
dialog.getWindow().findViewById(R.id.parentPanel).setPadding(0, 0, 0, 30);
dialog.getWindow().findViewById(R.id.button3).setOutlineProvider(null);
}
// Prevents screen overlay attack.
getWindow().setHideOverlayWindows(true);
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setFilterTouchesWhenObscured(true);
@@ -104,10 +120,10 @@ public class UnlaunchableAppActivity extends Activity
UNLAUNCHABLE_APP_WORK_PAUSED_TITLE, () -> getString(R.string.work_mode_off_title));
}
private String getDialogMessage() {
private String getDialogMessage(int dialogMessageString) {
return getSystemService(DevicePolicyManager.class).getResources().getString(
UNLAUNCHABLE_APP_WORK_PAUSED_MESSAGE,
() -> getString(R.string.work_mode_off_message));
() -> getString(dialogMessageString));
}
@Override
@@ -117,14 +133,27 @@ public class UnlaunchableAppActivity extends Activity
@Override
public void onClick(DialogInterface dialog, int which) {
if (mReason == UNLAUNCHABLE_REASON_QUIET_MODE && which == DialogInterface.BUTTON_POSITIVE) {
if (mReason != UNLAUNCHABLE_REASON_QUIET_MODE) {
return;
}
if (which == DialogInterface.BUTTON_POSITIVE) {
UserManager userManager = UserManager.get(this);
new Handler(Looper.getMainLooper()).post(
() -> userManager.requestQuietModeEnabled(
/* enableQuietMode= */ false, UserHandle.of(mUserId), mTarget));
} else if (which == DialogInterface.BUTTON_NEUTRAL) {
launchEmergencyDialer();
}
}
private void launchEmergencyDialer() {
startActivity(mTelecomManager.createLaunchEmergencyDialerIntent(
null /* number*/)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
| Intent.FLAG_ACTIVITY_CLEAR_TOP));
}
private static final Intent createBaseIntent() {
Intent intent = new Intent();
intent.setComponent(new ComponentName("android", UnlaunchableAppActivity.class.getName()));
@@ -139,9 +168,13 @@ public class UnlaunchableAppActivity extends Activity
return intent;
}
public static Intent createInQuietModeDialogIntent(int userId, IntentSender target) {
public static Intent createInQuietModeDialogIntent(int userId, IntentSender target,
ResolveInfo resolveInfo) {
Intent intent = createInQuietModeDialogIntent(userId);
intent.putExtra(Intent.EXTRA_INTENT, target);
if (resolveInfo != null) {
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, resolveInfo.getComponentInfo().packageName);
}
return intent;
}
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2022 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetTop="6dp"
android:insetBottom="6dp">
<shape android:shape="rectangle">
<corners android:radius="18dp"/>
<solid android:color="@android:color/system_accent3_100" />
</shape>
</inset>

View File

@@ -5329,6 +5329,10 @@
<string name="work_mode_off_message">Get access to your work apps and notifications</string>
<!-- Title for button to turn on work profile. [CHAR LIMIT=NONE] -->
<string name="work_mode_turn_on">Turn on</string>
<!-- Title for button to launch the personal safety app to make an emergency call -->
<string name="work_mode_emergency_call_button">Emergency</string>
<!-- Text shown in a dialog when the user tries to launch a disabled work profile app when work apps are paused-->
<string name="work_mode_dialer_off_message">Get access to your work apps and calls</string>
<!-- Title of the dialog that is shown when the user tries to launch a blocked application [CHAR LIMIT=50] -->
<string name="app_blocked_title">App is not available</string>

View File

@@ -30,7 +30,7 @@ please see styles_device_defaults.xml.
-->
<resources>
<!-- Global Theme Styles -->
<eat-comment />
<eat-comment/>
<style name="WindowTitleBackground">
<item name="background">@drawable/title_bar</item>
@@ -69,6 +69,19 @@ please see styles_device_defaults.xml.
<item name="needsDefaultBackgrounds">false</item>
</style>
<!-- Base style for the alert dialog with emergency call button -->
<style name="AlertDialogWithEmergencyButton" parent="AlertDialog">
<item name="buttonBarNeutralButtonStyle">@style/AlertDialogEmergencyButtonStyle</item>
</style>
<style name="AlertDialogEmergencyButtonStyle" parent="AlertDialogWithEmergencyButton">
<item name="background">@drawable/work_mode_emergency_button_background</item>
<item name="textColor">@color/text_color_on_accent_device_default</item>
<item name="paddingLeft">15dip</item>
<item name="paddingRight">15dip</item>
<item name="layout_marginStart">10dip</item>
</style>
<style name="Widget.PreferenceFrameLayout">
<item name="borderTop">0dip</item>
<item name="borderBottom">0dip</item>
@@ -77,7 +90,7 @@ please see styles_device_defaults.xml.
</style>
<!-- Base style for animations. This style specifies no animations. -->
<style name="Animation" />
<style name="Animation"/>
<!-- Standard animations for a full-screen window or activity. -->
<style name="Animation.Activity">
@@ -231,7 +244,7 @@ please see styles_device_defaults.xml.
</style>
<!-- A special animation value used internally for popup windows. -->
<style name="Animation.PopupWindow" />
<style name="Animation.PopupWindow"/>
<!-- Window animations used for action mode UI in overlay mode. -->
<style name="Animation.PopupWindow.ActionMode">
@@ -503,7 +516,8 @@ please see styles_device_defaults.xml.
<item name="textEditSidePasteWindowLayout">?attr/textEditSidePasteWindowLayout</item>
<item name="textEditSideNoPasteWindowLayout">?attr/textEditSideNoPasteWindowLayout</item>
<item name="textEditSuggestionItemLayout">?attr/textEditSuggestionItemLayout</item>
<item name="textEditSuggestionContainerLayout">?attr/textEditSuggestionContainerLayout</item>
<item name="textEditSuggestionContainerLayout">?attr/textEditSuggestionContainerLayout
</item>
<item name="textEditSuggestionHighlightStyle">?attr/textEditSuggestionHighlightStyle</item>
<item name="textCursorDrawable">?attr/textCursorDrawable</item>
<item name="breakStrategy">high_quality</item>
@@ -593,7 +607,8 @@ please see styles_device_defaults.xml.
<item name="weekNumberColor">#33FFFFFF</item>
<item name="weekSeparatorLineColor">#19FFFFFF</item>
<item name="selectedDateVerticalBar">@drawable/day_picker_week_view_dayline_holo</item>
<item name="weekDayTextAppearance">@style/TextAppearance.Small.CalendarViewWeekDayView</item>
<item name="weekDayTextAppearance">@style/TextAppearance.Small.CalendarViewWeekDayView
</item>
<item name="dateTextAppearance">?attr/textAppearanceSmall</item>
<item name="calendarViewMode">holo</item>
</style>
@@ -689,12 +704,12 @@ please see styles_device_defaults.xml.
</style>
<style name="Widget.ListView.DropDown">
<item name="cacheColorHint">@null</item>
<item name="cacheColorHint">@null</item>
<item name="divider">@drawable/divider_horizontal_bright_opaque</item>
</style>
<style name="Widget.ListView.Menu" parent="Widget.Holo.ListView">
<item name="cacheColorHint">@null</item>
<item name="cacheColorHint">@null</item>
<item name="scrollbars">vertical</item>
<item name="fadingEdge">none</item>
<!-- Light background for the list in menus, so the divider for bright themes -->
@@ -819,7 +834,7 @@ please see styles_device_defaults.xml.
</style>
<!-- Text Appearances -->
<eat-comment />
<eat-comment/>
<style name="TextAppearance">
<item name="textColor">?textColorPrimary</item>
@@ -878,9 +893,9 @@ please see styles_device_defaults.xml.
<item name="textColorLink">?textColorLinkInverse</item>
</style>
<style name="TextAppearance.Theme.Dialog" parent="TextAppearance.Theme" />
<style name="TextAppearance.Theme.Dialog" parent="TextAppearance.Theme"/>
<style name="TextAppearance.Widget" />
<style name="TextAppearance.Widget"/>
<style name="TextAppearance.Widget.Button" parent="TextAppearance.Small.Inverse">
<item name="textColor">@color/primary_text_light_nodisable</item>
@@ -946,22 +961,22 @@ please see styles_device_defaults.xml.
</style>
<!-- @hide -->
<style name="TextAppearance.SearchResult">
<item name="textStyle">normal</item>
<item name="textColor">?textColorPrimaryInverse</item>
<item name="textColorHint">?textColorHintInverse</item>
</style>
<style name="TextAppearance.SearchResult">
<item name="textStyle">normal</item>
<item name="textColor">?textColorPrimaryInverse</item>
<item name="textColorHint">?textColorHintInverse</item>
</style>
<!-- @hide -->
<style name="TextAppearance.SearchResult.Title">
<item name="textSize">18sp</item>
</style>
<!-- @hide -->
<style name="TextAppearance.SearchResult.Title">
<item name="textSize">18sp</item>
</style>
<!-- @hide -->
<style name="TextAppearance.SearchResult.Subtitle">
<item name="textSize">14sp</item>
<item name="textColor">?textColorSecondaryInverse</item>
</style>
<!-- @hide -->
<style name="TextAppearance.SearchResult.Subtitle">
<item name="textSize">14sp</item>
<item name="textColor">?textColorSecondaryInverse</item>
</style>
<style name="TextAppearance.WindowTitle">
<item name="textColor">#fff</item>
@@ -1165,7 +1180,7 @@ please see styles_device_defaults.xml.
</style>
<!-- Other Misc Styles -->
<eat-comment />
<eat-comment/>
<style name="MediaButton">
<item name="background">@null</item>
@@ -1298,10 +1313,12 @@ please see styles_device_defaults.xml.
<item name="textColor">?attr/textColorSecondary</item>
</style>
<style name="TextAppearance.Widget.Toolbar.Title" parent="TextAppearance.Widget.ActionBar.Title">
<style name="TextAppearance.Widget.Toolbar.Title"
parent="TextAppearance.Widget.ActionBar.Title">
</style>
<style name="TextAppearance.Widget.Toolbar.Subtitle" parent="TextAppearance.Widget.ActionBar.Subtitle">
<style name="TextAppearance.Widget.Toolbar.Subtitle"
parent="TextAppearance.Widget.ActionBar.Subtitle">
</style>
<style name="Widget.ActionButton">
@@ -1527,8 +1544,8 @@ please see styles_device_defaults.xml.
<!-- The style for normal action button on notification -->
<style name="NotificationAction" parent="Widget.Material.Light.Button.Borderless.Small">
<item name="textColor">@color/notification_action_button_text_color</item>
<item name="background">@drawable/notification_material_action_background</item>
<item name="textColor">@color/notification_action_button_text_color</item>
<item name="background">@drawable/notification_material_action_background</item>
</style>
<!-- The style for emphasized action button on notification: Colored bordered ink button -->
@@ -1539,6 +1556,6 @@ please see styles_device_defaults.xml.
<!-- The style for disabled action button on notification -->
<style name="NotificationTombstoneAction" parent="NotificationAction">
<item name="textColor">#555555</item>
<item name="textColor">#555555</item>
</style>
</resources>

View File

@@ -3100,6 +3100,10 @@
<java-symbol type="string" name="language_selection_title" />
<java-symbol type="string" name="search_language_hint" />
<!-- Work profile unlaunchable app alert dialog-->
<java-symbol type="style" name="AlertDialogWithEmergencyButton"/>
<java-symbol type="string" name="work_mode_dialer_off_message" />
<java-symbol type="string" name="work_mode_emergency_call_button" />
<java-symbol type="string" name="work_mode_off_title" />
<java-symbol type="string" name="work_mode_off_message" />
<java-symbol type="string" name="work_mode_turn_on" />

View File

@@ -284,7 +284,7 @@ class ActivityStartInterceptor {
IntentSender target = createIntentSenderForOriginalIntent(mCallingUid,
FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT);
mIntent = UnlaunchableAppActivity.createInQuietModeDialogIntent(mUserId, target);
mIntent = UnlaunchableAppActivity.createInQuietModeDialogIntent(mUserId, target, mRInfo);
mCallingPid = mRealCallingPid;
mCallingUid = mRealCallingUid;
mResolvedType = null;