Search in sources :

Example 21 with RequiresPermission

use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.

the class DeviceUtils method isSameDevice.

@RequiresPermission(allOf = { ACCESS_WIFI_STATE, INTERNET, CHANGE_WIFI_STATE })
public static boolean isSameDevice(final String uniqueDeviceId) {
    // {prefix}{type}{32id}
    if (TextUtils.isEmpty(uniqueDeviceId) && uniqueDeviceId.length() < 33)
        return false;
    if (uniqueDeviceId.equals(udid))
        return true;
    final String cachedId = UtilsBridge.getSpUtils4Utils().getString(KEY_UDID, null);
    if (uniqueDeviceId.equals(cachedId))
        return true;
    int st = uniqueDeviceId.length() - 33;
    String type = uniqueDeviceId.substring(st, st + 1);
    if (type.startsWith("1")) {
        String macAddress = getMacAddress();
        if (macAddress.equals("")) {
            return false;
        }
        return uniqueDeviceId.substring(st + 1).equals(getUdid("", macAddress));
    } else if (type.startsWith("2")) {
        final String androidId = getAndroidID();
        if (TextUtils.isEmpty(androidId)) {
            return false;
        }
        return uniqueDeviceId.substring(st + 1).equals(getUdid("", androidId));
    }
    return false;
}
Also used : SuppressLint(android.annotation.SuppressLint) RequiresPermission(androidx.annotation.RequiresPermission)

Example 22 with RequiresPermission

use of androidx.annotation.RequiresPermission in project Moneycim by volkansahin45.

the class CameraSourcePreview method startIfReady.

@RequiresPermission(Manifest.permission.CAMERA)
private void startIfReady() throws IOException, SecurityException {
    if (mStartRequested && mSurfaceAvailable) {
        mCameraSource.start(mSurfaceView.getHolder());
        if (mOverlay != null) {
            Size size = mCameraSource.getPreviewSize();
            int min = Math.min(size.getWidth(), size.getHeight());
            int max = Math.max(size.getWidth(), size.getHeight());
            if (isPortraitMode()) {
                // Swap width and height sizes when in portrait, since it will be rotated by
                // 90 degrees
                mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing());
            } else {
                mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing());
            }
            mOverlay.clear();
        }
        mStartRequested = false;
    }
}
Also used : Size(com.google.android.gms.common.images.Size) RequiresPermission(androidx.annotation.RequiresPermission)

Example 23 with RequiresPermission

use of androidx.annotation.RequiresPermission in project mopub-android-mediation by mopub.

the class CameraSource method start.

/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The preview
 * frames are not displayed.
 *
 * @throws IOException if the camera's preview texture or display could not be initialized
 */
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start() throws IOException {
    synchronized (mCameraLock) {
        if (mCamera != null) {
            return this;
        }
        mCamera = createCamera();
        // old version of Android. fall back to use SurfaceView.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
            mCamera.setPreviewTexture(mDummySurfaceTexture);
        } else {
            mDummySurfaceView = new SurfaceView(mContext);
            mCamera.setPreviewDisplay(mDummySurfaceView.getHolder());
        }
        mCamera.startPreview();
        mProcessingThread = new Thread(mFrameProcessor);
        mFrameProcessor.setActive(true);
        mProcessingThread.start();
    }
    return this;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) SurfaceView(android.view.SurfaceView) RequiresPermission(androidx.annotation.RequiresPermission)

Example 24 with RequiresPermission

use of androidx.annotation.RequiresPermission in project mopub-android-mediation by mopub.

the class CameraSourcePreview method startIfReady.

@RequiresPermission(Manifest.permission.CAMERA)
private void startIfReady() throws IOException, SecurityException {
    if (mStartRequested && mSurfaceAvailable) {
        mCameraSource.start(mSurfaceView.getHolder());
        if (mOverlay != null) {
            Size size = mCameraSource.getPreviewSize();
            int min = Math.min(size.getWidth(), size.getHeight());
            int max = Math.max(size.getWidth(), size.getHeight());
            if (isPortraitMode()) {
                // Swap width and height sizes when in portrait, since it will be rotated by
                // 90 degrees
                mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing());
            } else {
                mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing());
            }
            mOverlay.clear();
        }
        mStartRequested = false;
    }
}
Also used : Size(com.google.android.gms.common.images.Size) RequiresPermission(androidx.annotation.RequiresPermission)

Example 25 with RequiresPermission

use of androidx.annotation.RequiresPermission in project react-native-app-upgrade by songxiaoliang.

the class ApkInstallUtils method installAppSilentBelow24.

/**
 * 静默安装 App 在Android7.0以下起作用
 * <p>非 root 需添加权限
 * {@code <uses-permission android:name="android.permission.INSTALL_PACKAGES" />}</p>
 *
 * @param filePath 文件路径
 * @return {@code true}: 安装成功<br>{@code false}: 安装失败
 */
@RequiresPermission(INSTALL_PACKAGES)
private static boolean installAppSilentBelow24(Context context, String filePath) {
    File file = FileUtils.getFileByPath(filePath);
    if (!FileUtils.isFileExists(context, file)) {
        return false;
    }
    String pmParams = " -r " + getInstallLocationParams();
    StringBuilder command = new StringBuilder().append("LD_LIBRARY_PATH=/vendor/lib:/system/lib pm install ").append(pmParams).append(" ").append(filePath.replace(" ", "\\ "));
    ShellUtils.CommandResult commandResult = ShellUtils.execCommand(command.toString(), !isSystemApplication(context), true);
    return commandResult.successMsg != null && (commandResult.successMsg.contains("Success") || commandResult.successMsg.contains("success"));
}
Also used : File(java.io.File) RequiresPermission(androidx.annotation.RequiresPermission)

Aggregations

RequiresPermission (androidx.annotation.RequiresPermission)43 SuppressLint (android.annotation.SuppressLint)11 WifiManager (android.net.wifi.WifiManager)5 TelephonyManager (android.telephony.TelephonyManager)4 ActivityManager (android.app.ActivityManager)3 Intent (android.content.Intent)3 SurfaceTexture (android.graphics.SurfaceTexture)3 Vibrator (android.os.Vibrator)3 Size (com.google.android.gms.common.images.Size)3 TargetApi (android.annotation.TargetApi)2 ConnectivityManager (android.net.ConnectivityManager)2 NetworkInfo (android.net.NetworkInfo)2 Bundle (android.os.Bundle)2 PowerManager (android.os.PowerManager)2 SpannableString (android.text.SpannableString)2 Rational (android.util.Rational)2 Size (android.util.Size)2 SurfaceView (android.view.SurfaceView)2 CameraSelector (androidx.camera.core.CameraSelector)2 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)2