Fallback to AOSP eSOS settings page if OEM impl fails

When OEM eSOS implementation fails for any reason (app disabled,
misconfigured, etc), Emergency SOS settings should fallack to the
default settings page (rather than hiding the setting entirely)

Bug: 180959553
Test: robotests
Change-Id: I31c08449eff3f01d4c33bf827023f17beade93c2
This commit is contained in:
Fan Zhang
2021-03-10 21:45:19 +00:00
parent bf182903ed
commit 9fdceaea78
4 changed files with 123 additions and 4 deletions

View File

@@ -2902,6 +2902,12 @@
android:grantUriPermissions="true" android:grantUriPermissions="true"
android:exported="false"/> android:exported="false"/>
<provider
android:name=".emergency.EmergencyActionContentProvider"
android:authorities="com.android.settings.emergency"
android:permission="android.permission.CALL_PRIVILEGED"
android:exported="true"/>
<activity <activity
android:name=".wifi.RequestToggleWiFiActivity" android:name=".wifi.RequestToggleWiFiActivity"
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert" android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert"

View File

@@ -0,0 +1,112 @@
/*
* Copyright (C) 2021 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.
*/
package com.android.settings.emergency;
import static android.telecom.TelecomManager.EXTRA_CALL_SOURCE;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.telecom.PhoneAccount;
import android.telecom.TelecomManager;
import android.text.TextUtils;
import android.util.Log;
import com.android.settings.R;
import com.android.settingslib.emergencynumber.EmergencyNumberUtils;
/**
* ContentProvider to delegate emergency action work
*/
public class EmergencyActionContentProvider extends ContentProvider {
private static final String TAG = "EmergencyActionContentP";
private static final String ACTION_START_EMERGENCY_CALL =
"com.android.settings.emergency.MAKE_EMERGENCY_CALL";
@Override
public Bundle call(String authority, String method, String arg, Bundle extras) {
int uid = Binder.getCallingUid();
Log.d(TAG, "calling pid/uid" + Binder.getCallingPid() + "/" + uid);
if (!isEmergencyInfo(getContext())) {
throw new SecurityException("Uid is not allowed: " + uid);
}
if (!TextUtils.equals(method, ACTION_START_EMERGENCY_CALL)) {
throw new IllegalArgumentException("Unsupported operation");
}
placeEmergencyCall(getContext());
return new Bundle();
}
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
return null;
}
@Override
public String getType(Uri uri) {
return null;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
return 0;
}
private static boolean isEmergencyInfo(Context context) {
final int callingUid = Binder.getCallingUid();
final String callingPackage = context.getPackageManager().getPackagesForUid(callingUid)[0];
return TextUtils.equals(callingPackage,
context.getString(R.string.config_aosp_emergency_package_name));
}
private static void placeEmergencyCall(Context context) {
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
Log.i(TAG, "Telephony is not supported, skipping.");
return;
}
Bundle extras = new Bundle();
extras.putBoolean(TelecomManager.EXTRA_IS_USER_INTENT_EMERGENCY_CALL, true);
extras.putInt(EXTRA_CALL_SOURCE, TelecomManager.CALL_SOURCE_EMERGENCY_SHORTCUT);
TelecomManager telecomManager = context.getSystemService(TelecomManager.class);
EmergencyNumberUtils emergencyNumberUtils = new EmergencyNumberUtils(context);
telecomManager.placeCall(
Uri.fromParts(PhoneAccount.SCHEME_TEL, emergencyNumberUtils.getPoliceNumber(),
/* fragment= */ null), extras);
}
}

View File

@@ -49,11 +49,11 @@ public class EmergencyGestureEntrypointPreferenceController extends BasePreferen
final String emergencyGestureSettingsPackageName = context.getResources().getString( final String emergencyGestureSettingsPackageName = context.getResources().getString(
R.string.emergency_gesture_settings_package); R.string.emergency_gesture_settings_package);
if (!TextUtils.isEmpty(emergencyGestureSettingsPackageName)) { if (!TextUtils.isEmpty(emergencyGestureSettingsPackageName)) {
mUseCustomIntent = true;
// Use custom intent if it's configured and system can resolve it.
final Intent intent = new Intent(ACTION_EMERGENCY_GESTURE_SETTINGS) final Intent intent = new Intent(ACTION_EMERGENCY_GESTURE_SETTINGS)
.setPackage(emergencyGestureSettingsPackageName); .setPackage(emergencyGestureSettingsPackageName);
if (canResolveIntent(intent)) { if (canResolveIntent(intent)) {
// Use custom intent if it's configured and system can resolve it.
mUseCustomIntent = true;
mIntent = intent; mIntent = intent;
} }
} }

View File

@@ -105,7 +105,7 @@ public class EmergencyGestureEntrypointPreferenceControllerTest {
} }
@Test @Test
public void getAvailabilityStatus_noSuitableIntent_shouldReturnUnsupported() { public void getAvailabilityStatus_noSuitableIntent_shouldReturnAvailable() {
SettingsShadowResources.overrideResource( SettingsShadowResources.overrideResource(
R.bool.config_show_emergency_gesture_settings, R.bool.config_show_emergency_gesture_settings,
Boolean.TRUE); Boolean.TRUE);
@@ -117,7 +117,8 @@ public class EmergencyGestureEntrypointPreferenceControllerTest {
EmergencyGestureEntrypointPreferenceController controller = EmergencyGestureEntrypointPreferenceController controller =
new EmergencyGestureEntrypointPreferenceController(mContext, PREF_KEY); new EmergencyGestureEntrypointPreferenceController(mContext, PREF_KEY);
assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
assertThat(controller.mIntent).isNull();
} }
private void prepareCustomIntent() { private void prepareCustomIntent() {