package com.example.applock.allmanager;

import android.app.Activity;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.widget.ImageView;

import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

public class SoftLockPermission {
    public static boolean isGetUsagePermission(Context context) {
        AppOpsManager opsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);//应用操作权限
        int mode = opsManager.checkOpNoThrow("android:get_usage_stats", android.os.Process.myUid(), context.getPackageName());//检查是否有某项权限
        return mode == AppOpsManager.MODE_ALLOWED;//允许访问铭感权限
    }

    public static void requestOverlays(Activity activity, int requestCode) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + activity.getPackageName()));
        activity.startActivityForResult(intent, requestCode);
    }


    public static void requestUsage(Activity context, int requestCode) {
        Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
        context.startActivityForResult(intent, requestCode);
    }

    public static boolean isOverlays(Context context) {
        return Settings.canDrawOverlays(context);
    }//打开悬浮窗权限


    public static boolean allAllowPermission(Context context) {
        boolean getUsagePermission = SoftLockPermission.isGetUsagePermission(context);
        boolean overlays = SoftLockPermission.isOverlays(context);
        return getUsagePermission && overlays;
    }


}
