diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-03-21 17:00:57 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-03-21 17:00:57 +0000 |
commit | 25b094b0473bb52238d7d45d4ba69b0d9949121c (patch) | |
tree | 04343b4113154bbb3c47a92face3663d5bebbe33 /src/com/android | |
parent | 896ca5c67360077503aca1fbe3d6f90a0ad160de (diff) | |
parent | c98a56336fd49a8c5ea2834a141627d3cf0d8d6d (diff) |
Merge "Only allow primary users to block numbers" into nyc-dev
am: c98a563
* commit 'c98a56336fd49a8c5ea2834a141627d3cf0d8d6d':
Only allow primary users to block numbers
Diffstat (limited to 'src/com/android')
4 files changed, 60 insertions, 18 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 6c8d7708a..42bee1edf 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -59,7 +59,6 @@ import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; import com.android.dialer.filterednumber.BlockNumberDialogFragment; import com.android.dialer.filterednumber.FilteredNumbersUtil; -import com.android.dialer.filterednumber.MigrateBlockedNumbersDialogFragment; import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; import com.android.dialer.util.DialerUtils; @@ -156,7 +155,8 @@ public class CallDetailActivity extends AppCompatActivity PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation); mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); mCopyNumberActionItem.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); - mBlockNumberActionItem.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); + + updateBlockActionItemVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber); final boolean isVoicemailNumber = @@ -277,7 +277,9 @@ public class CallDetailActivity extends AppCompatActivity } }); + mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block); + updateBlockActionItemVisibility(View.VISIBLE); mBlockNumberActionItem.setOnClickListener(this); mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call); mEditBeforeCallActionItem.setOnClickListener(this); @@ -292,6 +294,13 @@ public class CallDetailActivity extends AppCompatActivity } } + private void updateBlockActionItemVisibility(int visibility) { + if (!FilteredNumberCompat.canAttemptBlockOperations(mContext)) { + visibility = View.GONE; + } + mBlockNumberActionItem.setVisibility(visibility); + } + @Override public void onResume() { super.onResume(); @@ -468,8 +477,6 @@ public class CallDetailActivity extends AppCompatActivity mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds( R.drawable.ic_call_detail_unblock, 0, 0, 0); } - - mBlockNumberActionItem.setVisibility(View.VISIBLE); } private void closeSystemDialogs() { diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index 750914bdf..baf2e1ab5 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -55,7 +55,6 @@ import com.android.dialer.compat.FilteredNumberCompat; import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.filterednumber.BlockNumberDialogFragment; import com.android.dialer.filterednumber.FilteredNumbersUtil; -import com.android.dialer.filterednumber.MigrateBlockedNumbersDialogFragment; import com.android.dialer.logging.Logger; import com.android.dialer.logging.ScreenEvent; import com.android.dialer.service.ExtendedBlockingButtonRenderer; @@ -346,7 +345,8 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder .setOnMenuItemClickListener(this); } - if (FilteredNumbersUtil.canBlockNumber(mContext, number, countryIso)) { + if (FilteredNumberCompat.canAttemptBlockOperations(mContext) + && FilteredNumbersUtil.canBlockNumber(mContext, number, countryIso)) { mFilteredNumberAsyncQueryHandler.isBlockedNumber( new FilteredNumberAsyncQueryHandler.OnCheckBlockedListener() { @Override diff --git a/src/com/android/dialer/compat/FilteredNumberCompat.java b/src/com/android/dialer/compat/FilteredNumberCompat.java index c6c714b27..532cec5ac 100644 --- a/src/com/android/dialer/compat/FilteredNumberCompat.java +++ b/src/com/android/dialer/compat/FilteredNumberCompat.java @@ -25,6 +25,7 @@ import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.UserManager; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.telecom.TelecomManager; @@ -293,4 +294,39 @@ public class FilteredNumberCompat { } return new Intent(context, BlockedNumbersSettingsActivity.class); } + + /** + * Method used to determine if block operations are possible. + * + * @param context The {@link Context}. + * @return {@code true} if the app and user can block numbers, {@code false} otherwise. + */ + public static boolean canAttemptBlockOperations(Context context) { + if (!CompatUtils.isNCompatible()) { + // Dialer blocking, must be primary user + return UserManagerCompat.isSystemUser( + (UserManager) context.getSystemService(Context.USER_SERVICE)); + } + + // Great Wall blocking, must be primary user and the default or system dialer + // TODO(maxwelb): check that we're the default or system Dialer + return BlockedNumbersSdkCompat.canCurrentUserBlockNumbers(context); + } + + /** + * Used to determine if the call blocking settings can be opened. + * + * @param context The {@link Context}. + * @return {@code true} if the current user can open the call blocking settings, {@code false} + * otherwise. + */ + public static boolean canCurrentUserOpenBlockSettings(Context context) { + if (!CompatUtils.isNCompatible()) { + // Dialer blocking, must be primary user + return UserManagerCompat.isSystemUser( + (UserManager) context.getSystemService(Context.USER_SERVICE)); + } + // BlockedNumberContract blocking, verify through Contract API + return BlockedNumbersSdkCompat.canCurrentUserBlockNumbers(context); + } } diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java index bbcbd49fc..fc689d037 100644 --- a/src/com/android/dialer/settings/DialerSettingsActivity.java +++ b/src/com/android/dialer/settings/DialerSettingsActivity.java @@ -94,22 +94,21 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { phoneAccountSettingsHeader.intent = phoneAccountSettingsIntent; target.add(phoneAccountSettingsHeader); } - if (isPrimaryUser) { + if (FilteredNumberCompat.canCurrentUserOpenBlockSettings(this)) { Header blockedCallsHeader = new Header(); blockedCallsHeader.titleRes = R.string.manage_blocked_numbers_label; blockedCallsHeader.intent = FilteredNumberCompat.createManageBlockedNumbersIntent(this); target.add(blockedCallsHeader); - - if (TelephonyManagerCompat.isTtyModeSupported(telephonyManager) - || TelephonyManagerCompat - .isHearingAidCompatibilitySupported(telephonyManager)) { - Header accessibilitySettingsHeader = new Header(); - Intent accessibilitySettingsIntent = - new Intent(TelecomManager.ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS); - accessibilitySettingsHeader.titleRes = R.string.accessibility_settings_title; - accessibilitySettingsHeader.intent = accessibilitySettingsIntent; - target.add(accessibilitySettingsHeader); - } + } + if (isPrimaryUser + && (TelephonyManagerCompat.isTtyModeSupported(telephonyManager) + || TelephonyManagerCompat.isHearingAidCompatibilitySupported(telephonyManager))) { + Header accessibilitySettingsHeader = new Header(); + Intent accessibilitySettingsIntent = + new Intent(TelecomManager.ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS); + accessibilitySettingsHeader.titleRes = R.string.accessibility_settings_title; + accessibilitySettingsHeader.intent = accessibilitySettingsIntent; + target.add(accessibilitySettingsHeader); } } |