Snap for 7883892 from ea216fd2f3 to sc-v2-release

Change-Id: I7a27b19ba3921c1a36ae2bb4efd458f4395f23ee
This commit is contained in:
Android Build Coastguard Worker
2021-11-04 23:10:52 +00:00
10 changed files with 336 additions and 73 deletions

View File

@@ -1921,9 +1921,6 @@
<!-- Bluetooth device details companion apps. The body of confirmation dialog for remove association. [CHAR LIMIT=60] -->
<string name="bluetooth_companion_app_body"><xliff:g id="app_name" example="App Name">%1$s</xliff:g> app will no longer connect to your <xliff:g id="device_name" example="Device Name">%2$s</xliff:g></string>
<!-- Bluetooth device details. The body of a confirmation dialog for unpairing a paired device. [CHAR LIMIT=NONE] -->
<string name="bluetooth_untethered_unpair_dialog_body"><xliff:g id="device_name" example="Jack's headphone">%1$s</xliff:g> will no longer be paired with any device linked to this account</string>
<!-- Bluetooth device details. In the confirmation dialog for unpairing a paired device, this is the label on the button that will complete the unpairing action. -->
<string name="bluetooth_unpair_dialog_forget_confirm_button">Forget device</string>
<!-- Bluetooth device details companion apps. In the confirmation dialog for removing an associated app, this is the label on the button that will complete the disassociate action. [CHAR LIMIT=80] -->
@@ -6354,8 +6351,8 @@
<string name="power_wifi">Wi\u2011Fi</string>
<!-- Label for power consumed by Bluetooth -->
<string name="power_bluetooth">Bluetooth</string>
<!-- Label for power consumed by Mobile network idle -->
<string name="power_cell">Mobile network standby</string>
<!-- Label for power consumed by Mobile network -->
<string name="power_cell">Mobile network</string>
<!-- Label for power consumed by Calling -->
<string name="power_phone">Voice calls</string>
<!-- Label for power consumed when Idle -->

View File

@@ -58,6 +58,7 @@ import androidx.preference.PreferenceManager;
import com.android.internal.util.ArrayUtils;
import com.android.settings.Settings.WifiSettingsActivity;
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.activityembedding.SplitStateObserver;
import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.core.OnActivityResultListener;
import com.android.settings.core.SettingsBaseActivity;
@@ -255,11 +256,8 @@ public class SettingsActivity extends SettingsBaseActivity
// Should happen before any call to getIntent()
getMetaData();
final Intent intent = getIntent();
if (shouldShowTwoPaneDeepLink(intent)) {
launchHomepageForTwoPaneDeepLink(intent);
finishAndRemoveTask();
return;
}
registerSplitStateObserverForTwoPaneDeepLink();
final FeatureFactory factory = FeatureFactory.getFactory(this);
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
@@ -364,6 +362,29 @@ public class SettingsActivity extends SettingsBaseActivity
}
}
private void registerSplitStateObserverForTwoPaneDeepLink() {
if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)) {
return;
}
final SplitStateObserver splitStateObserver = new SplitStateObserver(this /* activity*/,
true /* listenOnce */,
splitInfos -> {
if (!splitInfos.isEmpty()) {
// It's already in 2-pane and no need to go 2-pane deep link flow.
return;
}
if (shouldShowTwoPaneDeepLink(getIntent())) {
launchHomepageForTwoPaneDeepLink(getIntent());
finishAndRemoveTask();
return;
}
}
);
getLifecycle().addObserver(splitStateObserver);
}
private boolean isSubSettings(Intent intent) {
return this instanceof SubSettings ||
intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
@@ -413,10 +434,6 @@ public class SettingsActivity extends SettingsBaseActivity
}
private boolean shouldShowTwoPaneDeepLink(Intent intent) {
if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)) {
return false;
}
// Only starts trampoline for deep links. Should return false for all the cases that
// Settings app starts SettingsActivity or SubSetting by itself.
if (intent.getAction() == null) {
@@ -434,11 +451,6 @@ public class SettingsActivity extends SettingsBaseActivity
return false;
}
if (intent.getBooleanExtra(SettingsHomepageActivity.EXTRA_IS_FROM_SETTINGS_HOMEPAGE,
/* defaultValue */ false)) {
return false;
}
if (TextUtils.equals(intent.getAction(), Intent.ACTION_CREATE_SHORTCUT)) {
// Returns false to show full screen for Intent.ACTION_CREATE_SHORTCUT because
// - Launcher startActivityForResult for Intent.ACTION_CREATE_SHORTCUT and activity

View File

@@ -0,0 +1,81 @@
/*
* 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.activityembedding;
import static androidx.lifecycle.Lifecycle.Event.ON_START;
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
import android.app.Activity;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.util.Consumer;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.window.embedding.SplitController;
import androidx.window.embedding.SplitInfo;
import java.util.List;
/** A lifecycle-aware observer listens to active split state. */
public class SplitStateObserver implements LifecycleObserver, Consumer<List<SplitInfo>> {
private final Activity mActivity;
private final boolean mListenOnce;
private final SplitStateListener mListener;
private final SplitController mSplitController;
public SplitStateObserver(@NonNull Activity activity, boolean listenOnce,
@NonNull SplitStateListener listener) {
mActivity = activity;
mListenOnce = listenOnce;
mListener = listener;
mSplitController = SplitController.getInstance();
}
/**
* Start lifecycle event.
*/
@OnLifecycleEvent(ON_START)
public void onStart() {
mSplitController.addSplitListener(mActivity, ContextCompat.getMainExecutor(mActivity),
this);
}
/**
* Stop lifecycle event.
*/
@OnLifecycleEvent(ON_STOP)
public void onStop() {
mSplitController.removeSplitListener(this);
}
@Override
public void accept(List<SplitInfo> splitInfos) {
if (mListenOnce) {
mSplitController.removeSplitListener(this);
}
mListener.onSplitInfoChanged(splitInfos);
}
/** This interface makes as class that it wants to listen to {@link SplitInfo} changes. */
public interface SplitStateListener {
/** Receive a set of split info change */
void onSplitInfoChanged(List<SplitInfo> splitInfos);
}
}

View File

@@ -29,7 +29,6 @@ import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -73,8 +72,6 @@ public class ForgetDeviceDialogFragment extends InstrumentedDialogFragment {
};
Context context = getContext();
mDevice = getDevice(context);
final boolean untetheredHeadset = BluetoothUtils.getBooleanMetaData(
mDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
AlertDialog dialog = new AlertDialog.Builder(context)
.setPositiveButton(R.string.bluetooth_unpair_dialog_forget_confirm_button,
@@ -82,9 +79,7 @@ public class ForgetDeviceDialogFragment extends InstrumentedDialogFragment {
.setNegativeButton(android.R.string.cancel, null)
.create();
dialog.setTitle(R.string.bluetooth_unpair_dialog_title);
dialog.setMessage(context.getString(untetheredHeadset
? R.string.bluetooth_untethered_unpair_dialog_body
: R.string.bluetooth_unpair_dialog_body,
dialog.setMessage(context.getString(R.string.bluetooth_unpair_dialog_body,
mDevice.getName()));
return dialog;
}

View File

@@ -63,10 +63,6 @@ public class SettingsHomepageActivity extends FragmentActivity implements
private static final String TAG = "SettingsHomepageActivity";
// Additional extra of Settings#ACTION_SETTINGS_LARGE_SCREEN_DEEP_LINK.
// Put true value to the intent when startActivity for a deep link intent from this Activity.
public static final String EXTRA_IS_FROM_SETTINGS_HOMEPAGE = "is_from_settings_homepage";
// Additional extra of Settings#ACTION_SETTINGS_LARGE_SCREEN_DEEP_LINK.
// Set & get Uri of the Intent separately to prevent failure of Intent#ParseUri.
public static final String EXTRA_SETTINGS_LARGE_SCREEN_DEEP_LINK_INTENT_DATA =
@@ -268,11 +264,11 @@ public class SettingsHomepageActivity extends FragmentActivity implements
// Sender of intent may want to send intent extra data to the destination of targetIntent.
targetIntent.replaceExtras(intent);
targetIntent.putExtra(EXTRA_IS_FROM_SETTINGS_HOMEPAGE, true);
targetIntent.putExtra(SettingsActivity.EXTRA_IS_FROM_SLICE, false);
targetIntent.setData(intent.getParcelableExtra(
SettingsHomepageActivity.EXTRA_SETTINGS_LARGE_SCREEN_DEEP_LINK_INTENT_DATA));
// Set 2-pane pair rule for the deep link page.
ActivityEmbeddingRulesController.registerTwoPanePairRule(this,
getDeepLinkComponent(),

View File

@@ -19,6 +19,8 @@ package com.android.settings.wifi;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.IActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -29,11 +31,13 @@ import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.AlertActivity;
import com.android.settings.R;
@@ -63,6 +67,8 @@ public class RequestToggleWiFiActivity extends AlertActivity
private @NonNull WifiManager mWiFiManager;
private @NonNull CharSequence mAppLabel;
@VisibleForTesting
protected IActivityManager mActivityManager = ActivityManager.getService();
private int mState = STATE_UNKNOWN;
private int mLastUpdateState = STATE_UNKNOWN;
@@ -75,20 +81,8 @@ public class RequestToggleWiFiActivity extends AlertActivity
setResult(Activity.RESULT_CANCELED);
String packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME);
if (TextUtils.isEmpty(packageName)) {
finish();
return;
}
try {
ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(
packageName, 0);
mAppLabel = applicationInfo.loadSafeLabel(getPackageManager(),
PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX, PackageItemInfo.SAFE_LABEL_FLAG_TRIM
| PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE);
} catch (PackageManager.NameNotFoundException e) {
Log.e(LOG_TAG, "Couldn't find app with package name " + packageName);
mAppLabel = getAppLabel();
if (TextUtils.isEmpty(mAppLabel)) {
finish();
return;
}
@@ -140,7 +134,6 @@ public class RequestToggleWiFiActivity extends AlertActivity
@Override
protected void onStart() {
super.onStart();
mReceiver.register();
final int wifiState = mWiFiManager.getWifiState();
@@ -223,6 +216,32 @@ public class RequestToggleWiFiActivity extends AlertActivity
super.onStop();
}
@VisibleForTesting
protected CharSequence getAppLabel() {
String packageName;
try {
packageName = mActivityManager.getLaunchedFromPackage(getActivityToken());
if (TextUtils.isEmpty(packageName)) {
Log.d(LOG_TAG, "Package name is null");
return null;
}
} catch (RemoteException e) {
Log.e(LOG_TAG, "Can not get the package from activity manager");
return null;
}
try {
ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(
packageName, 0);
return applicationInfo.loadSafeLabel(getPackageManager(),
PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX, PackageItemInfo.SAFE_LABEL_FLAG_TRIM
| PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE);
} catch (PackageManager.NameNotFoundException e) {
Log.e(LOG_TAG, "Couldn't find app with package name " + packageName);
return null;
}
}
private void updateUi() {
if (mLastUpdateState == mState) {
return;

View File

@@ -16,9 +16,14 @@
package com.android.settings.wifi.addappnetworks;
import android.app.ActivityManager;
import android.app.IActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.RemoteException;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
@@ -48,12 +53,17 @@ public class AddAppNetworksActivity extends FragmentActivity {
@VisibleForTesting
final Bundle mBundle = new Bundle();
@VisibleForTesting
IActivityManager mActivityManager = ActivityManager.getService();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_panel);
showAddNetworksFragment();
if (!showAddNetworksFragment()) {
finish();
return;
}
getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
// Move the window to the bottom of screen, and make it take up the entire screen width.
@@ -67,13 +77,22 @@ public class AddAppNetworksActivity extends FragmentActivity {
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
showAddNetworksFragment();
if (!showAddNetworksFragment()) {
finish();
return;
}
}
@VisibleForTesting
void showAddNetworksFragment() {
protected boolean showAddNetworksFragment() {
String packageName = getCallingAppPackageName();
if (TextUtils.isEmpty(packageName)) {
Log.d(TAG, "Package name is null");
return false;
}
// TODO: Check the new intent status.
mBundle.putString(KEY_CALLING_PACKAGE_NAME, getCallingPackage());
mBundle.putString(KEY_CALLING_PACKAGE_NAME, packageName);
mBundle.putParcelableArrayList(Settings.EXTRA_WIFI_NETWORK_LIST,
getIntent().getParcelableArrayListExtra(Settings.EXTRA_WIFI_NETWORK_LIST));
@@ -86,5 +105,19 @@ public class AddAppNetworksActivity extends FragmentActivity {
} else {
((AddAppNetworksFragment) fragment).createContent(mBundle);
}
return true;
}
@VisibleForTesting
protected String getCallingAppPackageName() {
String packageName;
try {
packageName = mActivityManager.getLaunchedFromPackage(getActivityToken());
} catch (RemoteException e) {
Log.e(TAG, "Can not get the package from activity manager");
return null;
}
return packageName;
}
}

View File

@@ -98,20 +98,6 @@ public class ForgetDeviceDialogFragmentTest {
assertThat(mActivity.isFinishing()).isTrue();
}
@Test
public void createDialog_untetheredDevice_showUntetheredMessage() {
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
.thenReturn("true".getBytes());
FragmentController.setupFragment(mFragment, FragmentActivity.class,
0 /* containerViewId */, null /* bundle */);
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
assertThat(shadowDialog.getMessage()).isEqualTo(
mContext.getString(R.string.bluetooth_untethered_unpair_dialog_body, DEVICE_NAME));
}
@Test
public void createDialog_normalDevice_showNormalMessage() {
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))

View File

@@ -18,27 +18,70 @@ package com.android.settings.wifi.addappnetworks;
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Shadows.shadowOf;
import android.annotation.Nullable;
import android.app.IActivityManager;
import android.os.RemoteException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class AddAppNetworksActivityTest {
@Mock
private IActivityManager mIActivityManager;
private AddAppNetworksActivity mActivity;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mActivity = Robolectric.buildActivity(AddAppNetworksActivity.class).create().get();
mActivity.mActivityManager = mIActivityManager;
}
@Test
public void startActivity_withPackageName_bundleShouldHaveRightPackageName() {
final String packageName = RuntimeEnvironment.application.getPackageName();
final AddAppNetworksActivity activity =
Robolectric.buildActivity(AddAppNetworksActivity.class).create().get();
shadowOf(activity).setCallingPackage(packageName);
public void getCallingAppPackageName_nullPackageName_returnNotNull() {
fakeCallingPackage("com.android.settings");
activity.showAddNetworksFragment();
assertThat(mActivity.getCallingAppPackageName()).isNotNull();
}
assertThat(activity.mBundle.getString(AddAppNetworksActivity.KEY_CALLING_PACKAGE_NAME))
.isEqualTo(packageName);
@Test
public void getCallingAppPackageName_withPackageName_returnNull() {
fakeCallingPackage(null);
assertThat(mActivity.getCallingAppPackageName()).isNull();
}
@Test
public void showAddNetworksFragment_nullPackageName_returnFalse() {
fakeCallingPackage(null);
assertThat(mActivity.showAddNetworksFragment()).isFalse();
}
@Test
public void showAddNetworksFragment_withPackageName_returnTrue() {
fakeCallingPackage("com.android.settings");
assertThat(mActivity.showAddNetworksFragment()).isTrue();
}
private void fakeCallingPackage(@Nullable String packageName) {
try {
when(mIActivityManager.getLaunchedFromPackage(any())).thenReturn(packageName);
} catch (RemoteException e) {
// Do nothing.
}
}
}

View File

@@ -0,0 +1,101 @@
/*
* 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.wifi;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import android.annotation.Nullable;
import android.app.IActivityManager;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.RemoteException;
import androidx.test.core.app.ActivityScenario;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class RequestToggleWiFiActivityTest {
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Spy
private final Context mContext = ApplicationProvider.getApplicationContext();
@Mock
private WifiManager mWifiManager;
@Mock
private IActivityManager mIActivityManager;
private ActivityScenario<RequestToggleWiFiActivity> mActivityScenario;
private RequestToggleWiFiActivity mActivity;
@Before
public void setUp() {
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
when(mWifiManager.getWifiState()).thenReturn(WifiManager.WIFI_STATE_DISABLED);
mActivityScenario = ActivityScenario.launch(new Intent(WifiManager.ACTION_REQUEST_ENABLE));
mActivityScenario.onActivity(activity -> mActivity = activity);
}
@After
public void cleanUp() {
mActivity = null;
if (mActivityScenario != null) {
mActivityScenario.close();
}
}
@Test
public void getAppLabel_nullPackageName_returnNull() {
fakeCallingPackage(null);
assertThat(mActivity.getAppLabel()).isNull();
}
@Test
public void getAppLabel_settingsPackageName_returnNotNull() {
fakeCallingPackage("com.android.settings");
assertThat(mActivity.getAppLabel()).isNotNull();
}
private void fakeCallingPackage(@Nullable String packageName) {
assertThat(mActivity).isNotNull();
mActivity.mActivityManager = mIActivityManager;
try {
when(mIActivityManager.getLaunchedFromPackage(any())).thenReturn(packageName);
} catch (RemoteException e) {
// Do nothing.
}
}
}