diff options
11 files changed, 367 insertions, 55 deletions
diff --git a/res/values-mcc234/strings.xml b/res/values-mcc234/strings.xml new file mode 100644 index 0000000000..f7d0d33d0b --- /dev/null +++ b/res/values-mcc234/strings.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> +<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="cell_broadcast_settings">Emergency alerts</string> +</resources>
\ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 226398ea5e..811a44c7c5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -12198,15 +12198,39 @@ <string name="aware_summary_when_bedtime_on">Unavailable because bedtime mode is on</string> <!-- Bluetooth message permission alert for notification content [CHAR LIMIT=none] --> - <string name="bluetooth_message_access_notification_content">Untrusted device wants to access your messages. Tap for details.</string> + <string name="bluetooth_message_access_notification_content">A device wants to access your messages. Tap for details.</string> <!-- Bluetooth message permission alert for dialog title [CHAR LIMIT=none] --> <string name="bluetooth_message_access_dialog_title">Allow access to messages?</string> <!-- Bluetooth message permission alert for dialog content [CHAR LIMIT=none] --> - <string name="bluetooth_message_access_dialog_content">An untrusted Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your messages.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string> + <string name="bluetooth_message_access_dialog_content">A Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your messages.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string> <!-- Bluetooth phonebook permission alert for notification content [CHAR LIMIT=none] --> - <string name="bluetooth_phonebook_access_notification_content">Untrusted device wants to access your contacts and call log. Tap for details.</string> + <string name="bluetooth_phonebook_access_notification_content">A device wants to access your contacts and call log. Tap for details.</string> <!-- Bluetooth phonebook permission alert for dialog title [CHAR LIMIT=none] --> <string name="bluetooth_phonebook_access_dialog_title">Allow access to contacts and call log?</string> <!-- Bluetooth phonebook permission alert for dialog content [CHAR LIMIT=none] --> - <string name="bluetooth_phonebook_access_dialog_content">An untrusted Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your contacts and call log. This includes data about incoming and outgoing calls.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string> + <string name="bluetooth_phonebook_access_dialog_content">A Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your contacts and call log. This includes data about incoming and outgoing calls.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string> + + <!-- Label for button to not allow grant the permission for remote devices. [CHAR_LIMIT=50] --> + <string name="request_manage_bluetooth_permission_dont_allow">Don\u2019t allow</string> + + <!-- Bluetooth sim card permission alert for notification title [CHAR LIMIT=none] --> + <string name="bluetooth_sim_card_access_notification_title">SIM card access request</string> + <!-- Bluetooth sim card permission alert for notification content [CHAR LIMIT=none] --> + <string name="bluetooth_sim_card_access_notification_content">A device wants to access your SIM card. Tap for details.</string> + <!-- Bluetooth sim card permission alert for dialog title [CHAR LIMIT=none] --> + <string name="bluetooth_sim_card_access_dialog_title">Allow access to SIM card?</string> + <!-- Bluetooth sim card permission alert for dialog content [CHAR LIMIT=none] --> + <string name="bluetooth_sim_card_access_dialog_content">A Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access data on your SIM card. This includes your contacts.\n\nWhile connected, <xliff:g id="device_name" example="My device">%2$s</xliff:g> will receive all calls made to <xliff:g id="phone_number" example="0912345678">%3$s</xliff:g>.</string> + <!-- Bluetooth connect permission alert for notification title [CHAR LIMIT=none] --> + <string name="bluetooth_connect_access_notification_title">Bluetooth device available</string> + <!-- Bluetooth connect permission alert for notification content [CHAR LIMIT=none] --> + <string name="bluetooth_connect_access_notification_content">A device wants to connect. Tap for details.</string> + <!-- Bluetooth connect permission alert for dialog title [CHAR LIMIT=none] --> + <string name="bluetooth_connect_access_dialog_title">Connect to Bluetooth device?</string> + <!-- Bluetooth connect permission alert for dialog content [CHAR LIMIT=none] --> + <string name="bluetooth_connect_access_dialog_content"><xliff:g id="device_name" example="My device">%1$s</xliff:g> wants to connect to this phone.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string> + <!-- Strings for Dialog don't connect button --> + <string name="bluetooth_connect_access_dialog_negative">Don\u2019t connect</string> + <!-- Strings for Dialog connect button --> + <string name="bluetooth_connect_access_dialog_positive">Connect</string> </resources> diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java index 9afb2b4f2c..113922e230 100644 --- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java +++ b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java @@ -102,7 +102,7 @@ public class DeviceAdminAdd extends Activity { DevicePolicyManager mDPM; AppOpsManager mAppOps; DeviceAdminInfo mDeviceAdmin; - CharSequence mAddMsgText; + String mAddMsgText; String mProfileOwnerName; ImageView mAdminIcon; @@ -274,7 +274,11 @@ public class DeviceAdminAdd extends Activity { } } - mAddMsgText = getIntent().getCharSequenceExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION); + final CharSequence addMsgCharSequence = getIntent().getCharSequenceExtra( + DevicePolicyManager.EXTRA_ADD_EXPLANATION); + if (addMsgCharSequence != null) { + mAddMsgText = addMsgCharSequence.toString(); + } if (mAddingProfileOwner) { // If we're trying to add a profile owner and user setup hasn't completed yet, no @@ -628,7 +632,7 @@ public class DeviceAdminAdd extends Activity { } catch (Resources.NotFoundException e) { mAdminDescription.setVisibility(View.GONE); } - if (mAddMsgText != null) { + if (!TextUtils.isEmpty(mAddMsgText)) { mAddMsg.setText(mAddMsgText); mAddMsg.setVisibility(View.VISIBLE); } else { diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java b/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java index e40e30dd0a..211bcc6f4b 100644 --- a/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java +++ b/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java @@ -16,6 +16,8 @@ package com.android.settings.bluetooth; +import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; + import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; @@ -23,6 +25,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; +import android.telephony.TelephonyManager; import android.util.Log; import android.view.View; import android.widget.Button; @@ -30,12 +33,11 @@ import android.widget.TextView; import androidx.preference.Preference; +import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; import com.android.settings.R; -import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; - /** * BluetoothPermissionActivity shows a dialog for accepting incoming * profile connection request from untrusted devices. @@ -51,8 +53,6 @@ public class BluetoothPermissionActivity extends AlertActivity implements private TextView messageView; private Button mOkButton; private BluetoothDevice mDevice; - private String mReturnPackage = null; - private String mReturnClass = null; private int mRequestType = 0; private BroadcastReceiver mReceiver = new BroadcastReceiver() { @@ -89,21 +89,19 @@ public class BluetoothPermissionActivity extends AlertActivity implements } mDevice = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - mReturnPackage = i.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME); - mReturnClass = i.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME); mRequestType = i.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS); if(DEBUG) Log.i(TAG, "onCreate() Request type: " + mRequestType); if (mRequestType == BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION) { - showDialog(getString(R.string.bluetooth_connection_permission_request), mRequestType); + showDialog(getString(R.string.bluetooth_connect_access_dialog_title), mRequestType); } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) { showDialog(getString(R.string.bluetooth_phonebook_access_dialog_title), mRequestType); } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) { showDialog(getString(R.string.bluetooth_message_access_dialog_title), mRequestType); } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) { - showDialog(getString(R.string.bluetooth_sap_request), mRequestType); + showDialog(getString(R.string.bluetooth_sim_card_access_dialog_title), mRequestType); } else { Log.e(TAG, "Error: bad request type: " + mRequestType); @@ -136,9 +134,14 @@ public class BluetoothPermissionActivity extends AlertActivity implements p.mView = createSapDialogView(); break; } - p.mPositiveButtonText = getString(R.string.allow); + p.mPositiveButtonText = getString( + requestType == BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION + ? R.string.bluetooth_connect_access_dialog_positive : R.string.allow); p.mPositiveButtonListener = this; - p.mNegativeButtonText = getString(R.string.deny); + p.mNegativeButtonText = getString( + requestType == BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION + ? R.string.bluetooth_connect_access_dialog_negative + : R.string.request_manage_bluetooth_permission_dont_allow); p.mNegativeButtonListener = this; mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE); setupAlert(); @@ -159,8 +162,8 @@ public class BluetoothPermissionActivity extends AlertActivity implements String mRemoteName = Utils.createRemoteName(this, mDevice); mView = getLayoutInflater().inflate(R.layout.bluetooth_access, null); messageView = (TextView)mView.findViewById(R.id.message); - messageView.setText(getString(R.string.bluetooth_connection_dialog_text, - mRemoteName)); + messageView.setText(getString(R.string.bluetooth_connect_access_dialog_content, + mRemoteName, mRemoteName)); return mView; } @@ -184,10 +187,11 @@ public class BluetoothPermissionActivity extends AlertActivity implements private View createSapDialogView() { String mRemoteName = Utils.createRemoteName(this, mDevice); + TelephonyManager tm = getSystemService(TelephonyManager.class); mView = getLayoutInflater().inflate(R.layout.bluetooth_access, null); messageView = (TextView)mView.findViewById(R.id.message); - messageView.setText(getString(R.string.bluetooth_sap_acceptance_dialog_text, - mRemoteName, mRemoteName)); + messageView.setText(getString(R.string.bluetooth_sim_card_access_dialog_content, + mRemoteName, mRemoteName, tm.getLine1Number())); return mView; } @@ -202,14 +206,14 @@ public class BluetoothPermissionActivity extends AlertActivity implements sendReplyIntentToReceiver(false, true); } - private void sendReplyIntentToReceiver(final boolean allowed, final boolean always) { + @VisibleForTesting + void sendReplyIntentToReceiver(final boolean allowed, final boolean always) { Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); - if (mReturnPackage != null && mReturnClass != null) { - intent.setClassName(mReturnPackage, mReturnClass); + if (DEBUG) { + Log.i(TAG, "sendReplyIntentToReceiver() Request type: " + mRequestType + + " mReturnPackage"); } - if (DEBUG) Log.i(TAG, "sendReplyIntentToReceiver() Request type: " + mRequestType + - " mReturnPackage" + mReturnPackage + " mReturnClass" + mReturnClass); intent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT, allowed ? BluetoothDevice.CONNECTION_ACCESS_YES diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java index 177bd89355..791ade425b 100644 --- a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java +++ b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java @@ -56,8 +56,6 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver { Context mContext; int mRequestType; BluetoothDevice mDevice; - String mReturnPackage = null; - String mReturnClass = null; @Override public void onReceive(Context context, Intent intent) { @@ -77,11 +75,10 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver { mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); mRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION); - mReturnPackage = intent.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME); - mReturnClass = intent.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME); - if (DEBUG) Log.d(TAG, "onReceive request type: " + mRequestType + " return " - + mReturnPackage + "," + mReturnClass); + if (DEBUG) { + Log.d(TAG, "onReceive request type: " + mRequestType); + } // Even if the user has already made the choice, Bluetooth still may not know that if // the user preference data have not been migrated from Settings app's shared @@ -110,8 +107,6 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver { connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType); connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); - connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_PACKAGE_NAME, mReturnPackage); - connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_CLASS_NAME, mReturnClass); String deviceAddress = mDevice != null ? mDevice.getAddress() : null; String deviceName = mDevice != null ? mDevice.getName() : null; @@ -149,13 +144,17 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver { R.string.bluetooth_message_access_notification_content); break; case BluetoothDevice.REQUEST_TYPE_SIM_ACCESS: - title = context.getString(R.string.bluetooth_sap_request); - message = context.getString(R.string.bluetooth_sap_acceptance_dialog_text, + title = context.getString( + R.string.bluetooth_sim_card_access_notification_title); + message = context.getString( + R.string.bluetooth_sim_card_access_notification_content, deviceAlias, deviceAlias); break; default: - title = context.getString(R.string.bluetooth_connection_permission_request); - message = context.getString(R.string.bluetooth_connection_dialog_text, + title = context.getString( + R.string.bluetooth_connect_access_notification_title); + message = context.getString( + R.string.bluetooth_connect_access_notification_content, deviceAlias, deviceAlias); break; } @@ -230,7 +229,7 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver { LocalBluetoothManager bluetoothManager = Utils.getLocalBtManager(mContext); CachedBluetoothDeviceManager cachedDeviceManager = - bluetoothManager.getCachedDeviceManager(); + bluetoothManager.getCachedDeviceManager(); CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice); if (cachedDevice == null) { cachedDevice = cachedDeviceManager.addDevice(mDevice); @@ -288,13 +287,9 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver { private void sendReplyIntentToReceiver(final boolean allowed) { Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); - if (mReturnPackage != null && mReturnClass != null) { - intent.setClassName(mReturnPackage, mReturnClass); - } - intent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT, - allowed ? BluetoothDevice.CONNECTION_ACCESS_YES - : BluetoothDevice.CONNECTION_ACCESS_NO); + allowed ? BluetoothDevice.CONNECTION_ACCESS_YES + : BluetoothDevice.CONNECTION_ACCESS_NO); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType); mContext.sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_ADMIN); diff --git a/src/com/android/settings/bluetooth/DevicePickerActivity.java b/src/com/android/settings/bluetooth/DevicePickerActivity.java index 77e8ba4e1c..a4f025b267 100644 --- a/src/com/android/settings/bluetooth/DevicePickerActivity.java +++ b/src/com/android/settings/bluetooth/DevicePickerActivity.java @@ -16,6 +16,8 @@ package com.android.settings.bluetooth; +import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; + import android.os.Bundle; import androidx.fragment.app.FragmentActivity; @@ -31,6 +33,7 @@ public final class DevicePickerActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); setContentView(R.layout.bluetooth_device_picker); } } diff --git a/src/com/android/settings/bluetooth/DevicePickerFragment.java b/src/com/android/settings/bluetooth/DevicePickerFragment.java index ab8eea5db6..02b5d5c90f 100644 --- a/src/com/android/settings/bluetooth/DevicePickerFragment.java +++ b/src/com/android/settings/bluetooth/DevicePickerFragment.java @@ -27,12 +27,15 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.UserManager; +import android.util.Log; +import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; import androidx.annotation.VisibleForTesting; import com.android.settings.R; +import com.android.settings.password.PasswordUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.AbstractPreferenceController; @@ -48,10 +51,16 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment { @VisibleForTesting BluetoothProgressCategory mAvailableDevicesCategory; + @VisibleForTesting + Context mContext; + @VisibleForTesting + String mLaunchPackage; + @VisibleForTesting + String mLaunchClass; + @VisibleForTesting + String mCallingAppPackageName; private boolean mNeedAuth; - private String mLaunchPackage; - private String mLaunchClass; private boolean mScanAllowed; public DevicePickerFragment() { @@ -85,6 +94,13 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment { getActivity().setTitle(getString(R.string.device_picker)); UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); mScanAllowed = !um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH); + mCallingAppPackageName = PasswordUtils.getCallingAppPackageName( + getActivity().getActivityToken()); + if (!TextUtils.equals(mCallingAppPackageName, mLaunchPackage)) { + Log.w(TAG, "sendDevicePickedIntent() launch package name is not equivalent to" + + " calling package name!"); + } + mContext = getContext(); setHasOptionsMenu(true); } @@ -191,8 +207,11 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment { Intent intent = new Intent(BluetoothDevicePicker.ACTION_DEVICE_SELECTED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); if (mLaunchPackage != null && mLaunchClass != null) { - intent.setClassName(mLaunchPackage, mLaunchClass); + if (TextUtils.equals(mCallingAppPackageName, mLaunchPackage)) { + intent.setClassName(mLaunchPackage, mLaunchClass); + } } - getActivity().sendBroadcast(intent, Manifest.permission.BLUETOOTH_ADMIN); + + mContext.sendBroadcast(intent, Manifest.permission.BLUETOOTH_ADMIN); } } diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java index 8af9a7f190..9aefa7d4a3 100644 --- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java +++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java @@ -25,12 +25,15 @@ import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.os.UserManager; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import androidx.annotation.VisibleForTesting; + import com.android.settings.R; -import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.dashboard.RestrictedDashboardFragment; import com.android.settings.wifi.WifiConfigUiBase; import com.android.settings.wifi.WifiDialog; import com.android.settingslib.RestrictedLockUtils; @@ -51,15 +54,45 @@ import java.util.List; * future, please develop in * {@link com.android.settings.wifi.details2.WifiNetworkDetailsFragment2}. */ -public class WifiNetworkDetailsFragment extends DashboardFragment implements +public class WifiNetworkDetailsFragment extends RestrictedDashboardFragment implements WifiDialog.WifiDialogListener { private static final String TAG = "WifiNetworkDetailsFrg"; + @VisibleForTesting + boolean mIsUiRestricted; + private AccessPoint mAccessPoint; private WifiDetailPreferenceController mWifiDetailPreferenceController; private List<WifiDialog.WifiDialogListener> mWifiDialogListeners = new ArrayList<>(); + public WifiNetworkDetailsFragment() { + super(UserManager.DISALLOW_CONFIG_WIFI); + } + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + setIfOnlyAvailableForAdmins(true); + mIsUiRestricted = isUiRestricted(); + } + + @Override + public void onStart() { + super.onStart(); + if (mIsUiRestricted) { + restrictUi(); + } + } + + @VisibleForTesting + void restrictUi() { + if (!isUiRestrictedByOnlyAdmin()) { + getEmptyTextView().setText(R.string.wifi_empty_list_user_restricted); + } + getPreferenceScreen().removeAll(); + } + @Override public void onAttach(Context context) { mAccessPoint = new AccessPoint(context, getArguments()); @@ -102,9 +135,11 @@ public class WifiNetworkDetailsFragment extends DashboardFragment implements @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify); - item.setIcon(com.android.internal.R.drawable.ic_mode_edit); - item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + if (!mIsUiRestricted) { + MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify); + item.setIcon(com.android.internal.R.drawable.ic_mode_edit); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + } super.onCreateOptionsMenu(menu, inflater); } diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPermissionActivityTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPermissionActivityTest.java new file mode 100644 index 0000000000..35b8f1f00a --- /dev/null +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPermissionActivityTest.java @@ -0,0 +1,58 @@ +/* + * 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.bluetooth; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +import android.content.Context; +import android.content.Intent; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.util.ReflectionHelpers; + +@RunWith(RobolectricTestRunner.class) +public class BluetoothPermissionActivityTest { + + private BluetoothPermissionActivity mActivity; + private Context mContext; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = spy(RuntimeEnvironment.application); + mActivity = new BluetoothPermissionActivity(); + } + + @Test + public void sendBroadcastWithPermission() { + final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); + ReflectionHelpers.setField(mActivity, "mBase", mContext); + + mActivity.sendReplyIntentToReceiver(true, true); + + verify(mContext).sendBroadcast(intentCaptor.capture(), + eq("android.permission.BLUETOOTH_ADMIN")); + } +} diff --git a/tests/robotests/src/com/android/settings/bluetooth/DevicePickerFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/DevicePickerFragmentTest.java index feaf683142..a05ec87b71 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/DevicePickerFragmentTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/DevicePickerFragmentTest.java @@ -16,28 +16,46 @@ package com.android.settings.bluetooth; +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.bluetooth.BluetoothDevice; +import android.content.Context; +import android.content.Intent; + +import com.android.settingslib.bluetooth.CachedBluetoothDevice; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class DevicePickerFragmentTest { @Mock private BluetoothProgressCategory mAvailableDevicesCategory; + private DevicePickerFragment mFragment; + private Context mContext; @Before public void setUp() { MockitoAnnotations.initMocks(this); mFragment = new DevicePickerFragment(); - + mContext = spy(RuntimeEnvironment.application); + mFragment.mContext = mContext; mFragment.mAvailableDevicesCategory = mAvailableDevicesCategory; } @@ -49,4 +67,39 @@ public class DevicePickerFragmentTest { verify(mAvailableDevicesCategory).setProgress(true); } + + @Test + public void callingPackageIsEqualToLaunchPackage_sendBroadcastToLaunchPackage() { + final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class); + final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); + final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); + when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); + mFragment.mSelectedDevice = bluetoothDevice; + mFragment.mLaunchPackage = "com.android.settings"; + mFragment.mLaunchClass = "com.android.settings.bluetooth.BluetoothPermissionActivity"; + mFragment.mCallingAppPackageName = "com.android.settings"; + + mFragment.onDeviceBondStateChanged(cachedDevice, BluetoothDevice.BOND_BONDED); + + verify(mContext).sendBroadcast(intentCaptor.capture(), + eq("android.permission.BLUETOOTH_ADMIN")); + assertThat(intentCaptor.getValue().getComponent().getPackageName()) + .isEqualTo(mFragment.mLaunchPackage); + } + + @Test + public void callingPackageIsNotEqualToLaunchPackage_broadcastNotSend() { + final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class); + final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); + final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); + when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); + mFragment.mSelectedDevice = bluetoothDevice; + mFragment.mLaunchPackage = "com.fake.settings"; + mFragment.mLaunchClass = "com.android.settings.bluetooth.BluetoothPermissionActivity"; + mFragment.mCallingAppPackageName = "com.android.settings"; + + mFragment.onDeviceBondStateChanged(cachedDevice, BluetoothDevice.BOND_BONDED); + + verify(mContext, never()).sendBroadcast(intentCaptor.capture()); + } } diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java new file mode 100644 index 0000000000..f4693cf565 --- /dev/null +++ b/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java @@ -0,0 +1,99 @@ +/* + * 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.details; + +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +import android.view.Menu; +import android.view.MenuInflater; +import android.widget.TextView; + +import androidx.preference.PreferenceScreen; + +import com.android.settings.R; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; + +@RunWith(RobolectricTestRunner.class) +public class WifiNetworkDetailsFragmentTest { + + @Mock + Menu mMenu; + private WifiNetworkDetailsFragment mFragment; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mFragment = new WifiNetworkDetailsFragment(); + } + + @Test + public void onCreateOptionsMenu_uiRestricted_shouldNotAddEditMenu() { + mFragment.mIsUiRestricted = true; + + mFragment.onCreateOptionsMenu(mMenu, mock(MenuInflater.class)); + + verify(mMenu, never()).add(anyInt(), anyInt(), anyInt(), eq(R.string.wifi_modify)); + } + + @Test + public void restrictUi_shouldShowRestrictedText() { + final WifiNetworkDetailsFragmentTest.FakeFragment + fragment = spy(new WifiNetworkDetailsFragmentTest.FakeFragment()); + final PreferenceScreen screen = mock(PreferenceScreen.class); + final TextView restrictedText = mock(TextView.class); + doReturn(screen).when(fragment).getPreferenceScreen(); + doReturn(false).when(fragment).isUiRestrictedByOnlyAdmin(); + doReturn(restrictedText).when(fragment).getEmptyTextView(); + + fragment.restrictUi(); + + verify(restrictedText).setText(anyInt()); + } + + @Test + public void restrictUi_shouldRemoveAllPreferences() { + final WifiNetworkDetailsFragmentTest.FakeFragment + fragment = spy(new WifiNetworkDetailsFragmentTest.FakeFragment()); + final PreferenceScreen screen = mock(PreferenceScreen.class); + doReturn(screen).when(fragment).getPreferenceScreen(); + doReturn(true).when(fragment).isUiRestrictedByOnlyAdmin(); + + fragment.restrictUi(); + + verify(screen).removeAll(); + } + + // Fake WifiNetworkDetailsFragment to override the protected method as public. + public class FakeFragment extends WifiNetworkDetailsFragment { + @Override + public boolean isUiRestrictedByOnlyAdmin() { + return super.isUiRestrictedByOnlyAdmin(); + } + } +}
\ No newline at end of file |