From ab1f251defe8ee327917b1788f5702ae2c231a47 Mon Sep 17 00:00:00 2001 From: yuemingw Date: Wed, 10 Jan 2018 21:22:09 +0000 Subject: [PATCH] Change Settings to use URL_FILTERED and blocks menu options when DPC Apns are enforced. Change-Id: I64f55d9a625097baa17c0fa05250d944dea09896 Fix: 68208277 Test: manual --- src/com/android/settings/ApnPreference.java | 5 ++-- src/com/android/settings/ApnSettings.java | 29 ++++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/com/android/settings/ApnPreference.java b/src/com/android/settings/ApnPreference.java index 0111b26194c..4e89efc781c 100755 --- a/src/com/android/settings/ApnPreference.java +++ b/src/com/android/settings/ApnPreference.java @@ -16,11 +16,12 @@ package com.android.settings; +import static android.provider.Telephony.Carriers.FILTERED_URI; + import android.content.ContentUris; import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.provider.Telephony; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceViewHolder; import android.telephony.SubscriptionManager; @@ -118,7 +119,7 @@ public class ApnPreference extends Preference implements Context context = getContext(); if (context != null) { int pos = Integer.parseInt(getKey()); - Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos); + Uri url = ContentUris.withAppendedId(FILTERED_URI, pos); Intent editIntent = new Intent(Intent.ACTION_EDIT, url); editIntent.putExtra(ApnSettings.SUB_ID, mSubId); context.startActivity(editIntent); diff --git a/src/com/android/settings/ApnSettings.java b/src/com/android/settings/ApnSettings.java index d554301063c..3628121808e 100755 --- a/src/com/android/settings/ApnSettings.java +++ b/src/com/android/settings/ApnSettings.java @@ -16,6 +16,9 @@ package com.android.settings; +import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI; +import static android.provider.Telephony.Carriers.FILTERED_URI; + import android.app.Activity; import android.app.Dialog; import android.app.ProgressDialog; @@ -39,7 +42,6 @@ import android.os.UserManager; import android.provider.Telephony; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceGroup; -import android.support.v7.preference.PreferenceScreen; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; @@ -50,7 +52,6 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; -import android.widget.TextView; import android.widget.Toast; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; @@ -246,6 +247,17 @@ public class ApnSettings extends RestrictedSettingsFragment implements return null; } + private boolean isDpcApnEnforced() { + try (Cursor enforceCursor = getContentResolver().query(ENFORCE_MANAGED_URI, + null, null, null, null)) { + if (enforceCursor == null || enforceCursor.getCount() != 1) { + return false; + } + enforceCursor.moveToFirst(); + return enforceCursor.getInt(0) > 0; + } + } + private void fillList() { final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); final int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId() @@ -259,9 +271,9 @@ public class ApnSettings extends RestrictedSettingsFragment implements where.append(" AND NOT (type='ims')"); } - Cursor cursor = getContentResolver().query(Telephony.Carriers.CONTENT_URI, new String[] { - "_id", "name", "apn", "type", "mvno_type", "mvno_match_data"}, where.toString(), - null, Telephony.Carriers.DEFAULT_SORT_ORDER); + Cursor cursor = getContentResolver().query(FILTERED_URI, + new String[] {"_id", "name", "apn", "type", "mvno_type", "mvno_match_data"}, + where.toString(), null, Telephony.Carriers.DEFAULT_SORT_ORDER); if (cursor != null) { IccRecords r = null; @@ -343,15 +355,14 @@ public class ApnSettings extends RestrictedSettingsFragment implements @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (!mUnavailable) { + if (!mUnavailable && !isDpcApnEnforced()) { if (mAllowAddingApns) { menu.add(0, MENU_NEW, 0, getResources().getString(R.string.menu_new)) .setIcon(R.drawable.ic_menu_add_white) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } - menu.add(0, MENU_RESTORE, 0, - getResources().getString(R.string.menu_restore)) + menu.add(0, MENU_RESTORE, 0, getResources().getString(R.string.menu_restore)) .setIcon(android.R.drawable.ic_menu_upload); } @@ -387,7 +398,7 @@ public class ApnSettings extends RestrictedSettingsFragment implements @Override public boolean onPreferenceTreeClick(Preference preference) { int pos = Integer.parseInt(preference.getKey()); - Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos); + Uri url = ContentUris.withAppendedId(FILTERED_URI, pos); startActivity(new Intent(Intent.ACTION_EDIT, url)); return true; }