use of androidx.annotation.RequiresPermission in project Signal-Android by WhisperSystems.
the class Util method getDeviceNumber.
@RequiresPermission(anyOf = { android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.READ_SMS, android.Manifest.permission.READ_PHONE_NUMBERS })
@SuppressLint("MissingPermission")
public static Optional<Phonenumber.PhoneNumber> getDeviceNumber(Context context) {
try {
final String localNumber = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
final Optional<String> countryIso = getSimCountryIso(context);
if (TextUtils.isEmpty(localNumber))
return Optional.absent();
if (!countryIso.isPresent())
return Optional.absent();
return Optional.fromNullable(PhoneNumberUtil.getInstance().parse(localNumber, countryIso.get()));
} catch (NumberParseException e) {
Log.w(TAG, e);
return Optional.absent();
}
}
use of androidx.annotation.RequiresPermission in project Signal-Android by WhisperSystems.
the class WallpaperImageSelectionActivity method getIntent.
@RequiresPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
public static Intent getIntent(@NonNull Context context, @Nullable RecipientId recipientId) {
Intent intent = new Intent(context, WallpaperImageSelectionActivity.class);
intent.putExtra(EXTRA_RECIPIENT_ID, recipientId);
return intent;
}
use of androidx.annotation.RequiresPermission in project LshUtils by SenhLinsh.
the class PowerHelperEx method keepScreenOn.
@Deprecated
@RequiresPermission(Manifest.permission.WAKE_LOCK)
public void keepScreenOn() {
PowerManager powerManager = (PowerManager) getContext().getSystemService(Service.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, getClass().getSimpleName());
mWakeLock.setReferenceCounted(false);
mWakeLock.acquire();
}
use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.
the class DangerousUtils method setMobileDataEnabled.
/**
* Enable or disable mobile data.
* <p>Must hold {@code android:sharedUserId="android.uid.system"},
* {@code <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />}</p>
*
* @param enabled True to enabled, false otherwise.
* @return {@code true}: success<br>{@code false}: fail
*/
@RequiresPermission(MODIFY_PHONE_STATE)
public static boolean setMobileDataEnabled(final boolean enabled) {
try {
TelephonyManager tm = (TelephonyManager) Utils.getApp().getSystemService(Context.TELEPHONY_SERVICE);
if (tm == null)
return false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
tm.setDataEnabled(enabled);
return true;
}
Method setDataEnabledMethod = tm.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
setDataEnabledMethod.invoke(tm, enabled);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.
the class DangerousUtils method sendSmsSilent.
/**
* Send sms silently.
* <p>Must hold {@code <uses-permission android:name="android.permission.SEND_SMS" />}</p>
*
* @param phoneNumber The phone number.
* @param content The content.
*/
@RequiresPermission(SEND_SMS)
public static void sendSmsSilent(final String phoneNumber, final String content) {
if (TextUtils.isEmpty(content))
return;
PendingIntent sentIntent = PendingIntent.getBroadcast(Utils.getApp(), 0, new Intent("send"), 0);
SmsManager smsManager = SmsManager.getDefault();
if (content.length() >= 70) {
List<String> ms = smsManager.divideMessage(content);
for (String str : ms) {
smsManager.sendTextMessage(phoneNumber, null, str, sentIntent, null);
}
} else {
smsManager.sendTextMessage(phoneNumber, null, content, sentIntent, null);
}
}
Aggregations