Commit 7ac1bdac by 郑鹏

修复bug,适配机型

parent 3eecf6d3
......@@ -4,8 +4,10 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="delegatedBuild" value="false" />
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
......@@ -16,6 +18,7 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="testRunner" value="PLATFORM" />
</GradleProjectSettings>
</option>
</component>
......
......@@ -51,10 +51,8 @@ android {
}
dependencies {
implementation fileTree(dir:'libs',include:['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
......@@ -104,7 +102,7 @@ ext {
GITHUB_REPO_PATH = "../../androidlibrary"
PUBLISH_GROUP_ID = 'cn.dankal.android'
PUBLISH_ARTIFACT_ID = 'launcher'
PUBLISH_VERSION = '1.3.9.1'
PUBLISH_VERSION = '1.4.1.1'
}
uploadArchives {
......
......@@ -150,7 +150,7 @@ public class CellLayout extends ViewGroup {
private boolean mDragging = false;
private final TimeInterpolator mEaseOutInterpolator;
private final ShortcutAndWidgetContainer mShortcutsAndWidgets;
public final ShortcutAndWidgetContainer mShortcutsAndWidgets;
@Retention(RetentionPolicy.SOURCE)
@IntDef({WORKSPACE, HOTSEAT, FOLDER})
......@@ -2444,25 +2444,31 @@ public class CellLayout extends ViewGroup {
int numRows = mLauncher.getDeviceProfile().inv.numRows;
if (mShortcutsAndWidgets != null) {
ItemInfo itemInfo = mShortcutsAndWidgets.getLastItemInfo();
Log.i("launcher_shortcut_index", "上一个应用:名字" + itemInfo.title + "坐标(" + itemInfo.cellX + "," + itemInfo.cellY + ")");
if (itemInfo != null) {
if (itemInfo.cellY + itemInfo.spanY - 1 + spanY >= numRows && itemInfo.cellX + itemInfo.spanX - 1 + spanX >= numColumns) {
// 需要添加的cell长度已经不足以放下
Logger.e(TAG, "itemInfo.cellY(" + itemInfo.cellY + ") + itemInfo.spanY(" + itemInfo.spanY + ") - 1 + " + spanY + " >= " + numRows);
Log.i("launcher_shortcut_index", "不足放下itemInfo.cellY(" + itemInfo.cellY + ") + itemInfo.spanY(" + itemInfo.spanY + ") - 1 + " + spanY + " >= " + numRows);
return false;
}
if (itemInfo.cellX + itemInfo.spanX - 1 + spanX < numColumns) {
cellXY[0] = itemInfo.cellX + itemInfo.spanX;
if (spanY == 1) {
cellXY[1] = itemInfo.cellY;
Log.i("launcher_shortcut_index", "当前图标坐标:x" + cellXY[0] + "\ty" + cellXY[1]);
return true;
}else if (itemInfo.cellY + itemInfo.spanY - 1 + spanY >= numRows){
} else if (itemInfo.cellY + itemInfo.spanY - 1 + spanY >= numRows) {
Log.i("launcher_shortcut_index", "不足放下itemInfo.cellY(" + itemInfo.cellY + ") + itemInfo.spanY(" + itemInfo.spanY + ") - 1 + " + spanY + " >= " + numRows);
Logger.e(TAG, "itemInfo.cellY(" + itemInfo.cellY + ") + itemInfo.spanY(" + itemInfo.spanY + ") - 1 + " + spanY + " >= " + numRows);
return false;
}
} else if (itemInfo.cellY + itemInfo.spanY - 1 + spanY < numRows){
} else if (itemInfo.cellY + itemInfo.spanY - 1 + spanY < numRows) {
cellXY[0] = 0;
cellXY[1] = itemInfo.cellY + 1;
Log.i("launcher_shortcut_index", "当前图标坐标:x" + cellXY[0] + "\ty" + cellXY[1]);
return true;
// 在最后一个cell的末尾添加不了 那就在下一行计算
}
......
......@@ -169,7 +169,7 @@ public class FastBitmapDrawable extends Drawable {
canvas.drawBitmap(mBitmap, null, bounds, mPaint);
if (info != null) {
if (info != null && info.getIntent()!=null) {
ManagementInfo managementInfo = LauncherManager.getInstance().getManageAppInfo(info.getIntent().getComponent().getPackageName());
if (managementInfo != null) {
......
......@@ -21,6 +21,7 @@ import android.os.StrictMode;
import android.provider.MediaStore;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
......@@ -94,6 +95,12 @@ public class LockScreenActivity extends BaseActivity implements View.OnClickList
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (LauncherManager.mCustomDialog != null) {
LauncherManager.mCustomDialog.dismiss();
LauncherManager.mCustomDialog = null;
Log.i("qqqqqqqqqqqq", "LockScreenActivity关闭了对话框");
}
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();
......@@ -129,6 +136,12 @@ public class LockScreenActivity extends BaseActivity implements View.OnClickList
@Override
protected void onNewIntent(Intent intent) {
if (LauncherManager.mCustomDialog != null) {
LauncherManager.mCustomDialog.dismiss();
LauncherManager.mCustomDialog = null;
Log.i("qqqqqqqqqqqq", "LockScreenActivity关闭了进度条"+Thread.currentThread());
}
if (lockMode != LauncherManager.getInstance().getLockScreenMode()) {
lockMode = LauncherManager.getInstance().getLockScreenMode();
......@@ -267,7 +280,7 @@ public class LockScreenActivity extends BaseActivity implements View.OnClickList
} else if (v == ivCamera) {
// Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)== PackageManager.PERMISSION_GRANTED){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String rootPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();
......@@ -280,8 +293,8 @@ public class LockScreenActivity extends BaseActivity implements View.OnClickList
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imagePath));// 设置图片输出路径
imageCaptureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); //
startActivity(imageCaptureIntent);
}else {
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},100);
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
}
} else if (v == ivMessage) {
......@@ -315,7 +328,7 @@ public class LockScreenActivity extends BaseActivity implements View.OnClickList
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (imagePath!=null){
if (imagePath != null) {
try {
MediaStore.Images.Media.insertImage(getContentResolver(), imagePath.getAbsolutePath(), imagePath.getName(), null);//图片插入到系统图库
} catch (FileNotFoundException e) {
......@@ -323,7 +336,7 @@ public class LockScreenActivity extends BaseActivity implements View.OnClickList
}
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + imagePath.getAbsolutePath())));//通知图库刷新
imagePath=null;
imagePath = null;
}
}
......
......@@ -214,6 +214,10 @@ public class ShortcutAndWidgetContainer extends ViewGroup {
return mLastItemInfo;
}
public void setLastItemInfo(ItemInfo mLastItemInfo) {
this.mLastItemInfo = mLastItemInfo;
}
@Override
public void cancelLongPress() {
super.cancelLongPress();
......
......@@ -4,20 +4,40 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;
import com.android.launcher3.R;
import com.android.launcher3.debug.CustomDialog;
import com.android.launcher3.manager.LauncherManager;
import com.android.launcher3.util.PermissionUtil;
import com.android.launcher3.util.UIExecutor;
/**
* 开机自启动接收器
*/
public class AutoRunReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context mContext, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
//PermissionUtil.initLauncherIconIsShow(mContext,true);
Intent intent2 = new Intent(mContext, ListenerAppService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mContext.startForegroundService(intent2);
} else {
mContext.startService(intent2);
}
try {
if (LauncherManager.mCustomDialog == null) {
LauncherManager.mCustomDialog = new CustomDialog(mContext, R.layout.activity_clock_alarm);
LauncherManager.mCustomDialog.show();
Log.i("launch_debug_show", "开机显示了进度条");
}
} catch (Exception e) {
e.printStackTrace();
}
//重启之后启动桌面
LauncherManager.getInstance().backLauncherHome(mContext.getApplicationContext());
}
}
}
package com.android.launcher3.accessibility;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
......@@ -19,7 +20,11 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.WindowManager;
import com.android.launcher3.R;
import com.android.launcher3.debug.CustomDialog;
import com.android.launcher3.manager.ColumnDef;
import com.android.launcher3.manager.Constants;
import com.android.launcher3.manager.LauncherManager;
......@@ -27,8 +32,13 @@ import com.android.launcher3.manager.ManagementInfo;
import com.android.launcher3.model.ConfigManager;
import com.android.launcher3.util.Logger;
import com.android.launcher3.util.NotificationUtils;
import com.android.launcher3.util.PermissionUtil;
import com.android.launcher3.util.SystemUtils;
import com.android.launcher3.util.UIExecutor;
import com.android.launcher3.util.WeakHandler;
import org.json.JSONObject;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
......@@ -71,6 +81,7 @@ public class ListenerAppService extends Service {
private ExecutorService executors;
@SuppressLint("HandlerLeak")
private WeakHandler handler = new WeakHandler(this) {
@Override
public void handleMessage(Message msg) {
......@@ -143,7 +154,7 @@ public class ListenerAppService extends Service {
//动态注册广播
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
// intentFilter.addAction(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_USER_PRESENT);
// intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
//启动广播
......@@ -216,24 +227,36 @@ public class ListenerAppService extends Service {
Logger.e(TAG, action);
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
if (!LauncherManager.getInstance().getExitState()) {
String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
if (reason != null) {
Logger.e(TAG, action + "\t" + reason);
if (reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
//PermissionUtil.initLauncherIconIsShow(context,false);
// "Home键被监听"
if (!LauncherManager.getInstance().isForceLock()) {
Log.i("launch_debug_show", "Home键监听");
showProgress(context);
LauncherManager.getInstance().backLauncherHome(getApplicationContext());
} else {
// LauncherManager.getInstance().relockScreen();
showProgress(context);
LauncherManager.getInstance().backLauncherHome(getApplicationContext());
LauncherManager.getInstance().relockScreen();
}
} else if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
} else if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {//多任务监听
if (!LauncherManager.getInstance().isForceLock()) {
Log.i("launch_debug_show", "多任务按钮监听");
showProgress(context);
LauncherManager.getInstance().backLauncherHome(getApplicationContext());
} else {
// LauncherManager.getInstance().relockScreen();
showProgress(context);
LauncherManager.getInstance().backLauncherHome(getApplicationContext());
LauncherManager.getInstance().relockScreen();
}
} else if (reason.equals("globalactions")) {//电源键被长按
Log.i("launch_debug_show", "电源键被长按");
}
}
}
......@@ -251,6 +274,21 @@ public class ListenerAppService extends Service {
}
private void showProgress(Context context) {
if (SystemUtils.isMEIZU()) {
return;
}
try {
if (LauncherManager.mCustomDialog == null) {
LauncherManager.mCustomDialog = new CustomDialog(context, R.layout.activity_clock_alarm);
LauncherManager.mCustomDialog.show();
Log.i("launch_debug_show", "显示了进度条");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public class CheckAppAsyncTask extends AsyncTask<Void, Void, Integer> {
private WeakHandler handler;
......@@ -312,8 +350,10 @@ public class ListenerAppService extends Service {
lastUseAppControlTimeStamp = currentMills;
if (topActivity.equals(context.getPackageName()))
Log.i("launch_debug_show", "当前顶部包名" + topActivity + "****" + "当前应用包名" + context.getPackageName());
if (topActivity.equals(context.getPackageName())) {
return -1;
}
if (LauncherManager.getInstance().isInterceptSystemSetting() && "com.android.settings".equals(topActivity)) {
......@@ -323,7 +363,6 @@ public class ListenerAppService extends Service {
ManagementInfo appinfo = LauncherManager.getInstance().getManageAppInfo(topActivity);
if (!LauncherManager.getInstance().isSafePackageName(topActivity) && !LauncherManager.getInstance().isSystemPackageName(topActivity)) {
if (appinfo != null) {
if (appinfo.getLock() == ColumnDef.LockApp.LOCKED) {
......@@ -344,7 +383,8 @@ public class ListenerAppService extends Service {
}
}
} else {
return APP_UNCLASS_TYPE;
//return APP_UNCLASS_TYPE;
return -1;
}
}
} else {
......@@ -364,6 +404,13 @@ public class ListenerAppService extends Service {
if (code != -1) {
handler.sendEmptyMessage(code);
}
/* if (code == 200) {
if (LauncherManager.mCustomDialog != null) {
LauncherManager.mCustomDialog.dismiss();
LauncherManager.mCustomDialog = null;
Log.i("launch_debug_show", "关闭了进度条=" + Thread.currentThread());
}
}*/
}
}
}
......
......@@ -20,6 +20,9 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityWindowInfo;
import android.widget.Toast;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.auto_get_permission.GeneralAutoGetPermission;
......@@ -54,9 +57,13 @@ import io.reactivex.schedulers.Schedulers;
public class PermissionOpenAccessiblityService extends AccessibilityService {
private static final String TAG = "PermissionOpenAccessiblityService";
private static final String TAG_TOW = "permission_show_info";
private BaseAutoGetPermission permissionGetter;
// private boolean breadWhile = false;
private Handler handler = new Handler(Looper.getMainLooper());
@Override
protected void onServiceConnected() {
super.onServiceConnected();
......@@ -97,28 +104,71 @@ public class PermissionOpenAccessiblityService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
//监听魅族默认桌面选择
Logger.e(TAG, "onAccessibilityEvent " + event.toString());
if (LauncherManager.getInstance().isInterceptSystemSetting())
AccessibilityNodeInfo rowNode = getRootInActiveWindow();//获取当前屏幕所有节点
if (rowNode != null) {
recycle(event, rowNode);
}
Log.i(TAG_TOW, "==============================================");
if (LauncherManager.getInstance().isInterceptSystemSetting()) {
return;
}
if (event == null || event.getClassName() == null) {
return;
}
if ((event.getPackageName().toString().equals(getApplicationContext().getPackageName()) && !TextUtils.isEmpty(event.getClassName()) && event.getClassName().toString().equals("android.widget.LinearLayout"))) {
Log.i("reqeustAutoStartUp", "GLOBAL_ACTION_BACK==返回");
performGlobalAction(GLOBAL_ACTION_BACK);
return;
}
Log.i("reqeustAutoStartUp", "event.getEventType()" + event.getEventType());
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
permissionGetter.operateAccessibilityEvent(event);
}
/* if (SystemUtils.isMEIZU()) {//处理魅族桌面
handlerMeizhuDefaultDesktop(event);
}*/
}
private boolean mIsSelectDefaultUse = false;
private void handlerMeizhuDefaultDesktop(AccessibilityEvent event) {
//点击事件
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
AccessibilityNodeInfo rowNode = event.getSource();
//先判断,默认使用改应用是否勾选
List<AccessibilityNodeInfo> selectViews = rowNode.findAccessibilityNodeInfosByText("默认使用该应用");
if (selectViews != null && selectViews.size() > 0) {
AccessibilityNodeInfo selectView = selectViews.get(0);
if (selectView.isChecked()) {
mIsSelectDefaultUse = true;
}
}
if (mIsSelectDefaultUse) {
AccessibilityNodeInfo nodeInfo = event.getSource();
if (nodeInfo.getText().equals("倍知守护孩子端")) {
Log.i("zzzzzzzzzzzzzzzzzzzz", "默认桌面设置成功");
PermissionUtil.mIsDefaultDesktop = true;
mIsSelectDefaultUse = false;
}
}
}
}
@Override
......@@ -140,4 +190,36 @@ public class PermissionOpenAccessiblityService extends AccessibilityService {
super.onDestroy();
}
public void recycle(AccessibilityEvent event, AccessibilityNodeInfo info) {
if (info.getChildCount() == 0) {
Log.i(TAG_TOW, "child widget----------------------------" + info.getClassName());
Log.i(TAG_TOW, "showDialog:" + info.canOpenPopup());
Log.i(TAG_TOW, "Text:" + info.getText());
Log.i(TAG_TOW, "windowId:" + info.getWindowId());
} else {
for (int i = 0; i < info.getChildCount(); i++) {
if (info.getChild(i) != null) {
recycle(event, info.getChild(i));
}
}
}
try {
Log.i("reqeustAutoStartUp", "当前界面包名:" + event.getPackageName() + "\n当前应用的包名:" + getApplicationContext().getPackageName());
Log.i("reqeustAutoStartUp", "当前界面类名:" + event.getClassName() + "\n当前应用类:" + "android.widget.LinearLayout");
//判断当前界面
if (event.getPackageName().equals("android")) {
Log.i("qqqqqqqqqqqqqqqqqqqq", "在系统界面");
PermissionUtil.isSystemUI = true;
} else {
PermissionUtil.isSystemUI = false;
}
} catch (Exception e) {
e.printStackTrace();
PermissionUtil.isSystemUI = false;
}
}
}
package com.android.launcher3.accessibility;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;
import com.android.launcher3.R;
import com.android.launcher3.debug.CustomDialog;
import com.android.launcher3.manager.LauncherManager;
import com.android.launcher3.util.PermissionUtil;
/**
* 关机接收器
*/
public class StopRunReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context mContext, Intent intent) {
Log.i("launch_debug_show", "关机1");
if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)){//关机
/**
* 隐藏图标
*/
//PermissionUtil.initLauncherIconIsShow(mContext,false);
Log.i("launch_debug_show", "关机2");
}
}
}
......@@ -10,6 +10,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.Settings;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
......@@ -20,23 +21,25 @@ import com.android.launcher3.util.Logger;
import com.android.launcher3.util.PermissionUtil;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BACK;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_HOME;
public abstract class BaseAutoGetPermission {
// 设备管理器
// 设备管理器
public static final int STEP_REQUEST_DEVICE_ADMIN = 1;
// 自启动
// 自启动
public static final int STEP_REQUEST_AUTO_STARTUP = 2;
// 忽略电量优化
// 忽略电量优化
public static final int STEP_REQUEST_BATTERY_OPTIMIZE = 3;
// 使用记录访问权限
public static final int STEP_REQUEST_APP_USAGE= 4;
// 关闭USB调试
// 使用记录访问权限
public static final int STEP_REQUEST_APP_USAGE = 4;
// 关闭USB调试
public static final int STEP_REQUEST_CLOSE_USB = 5;
// 通知访问使用权
public static final int STEP_REQUEST_NOTIFICATION_MANAGER= 6;
// 默认桌面
// 通知访问使用权
public static final int STEP_REQUEST_NOTIFICATION_MANAGER = 6;
// 默认桌面
public static final int STEP_REQUEST_DEFAULT_LAUNCHER = 7;
......@@ -44,9 +47,9 @@ public abstract class BaseAutoGetPermission {
public static final long MAX_SEARCH_TIME = 4000;
public static final int BREAK_WHILE = 2;
// public static String appName = "倍知守护孩子端";
public static String appName = "倍知守护孩子端";
public static String appName = "dankal_launcher";
//public static String appName = "dankal_launcher";
public boolean isRunning;
private KToast toast;
......@@ -74,8 +77,12 @@ public abstract class BaseAutoGetPermission {
handler.sendEmptyMessageDelayed(0, 1000);
// Logger.e(TAG, "onServiceConnected\t");
service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
showToastLong("辅助权限设置已开启,请根据提示点击,如无提示请等待片刻");
if (toast != null) {
toast.dismiss();
toast = null;
}
toast = new KToast(service.getApplicationContext());
showToastLongTow("辅助权限设置已开启,请根据提示点击,\n如无提示请等稍等 或 手动返回权限设置页面");
}
private boolean isFinish = false;
......@@ -92,6 +99,8 @@ public abstract class BaseAutoGetPermission {
public void operateAccessibilityEvent(AccessibilityEvent event) {
Log.i("reqeustAutoStartUp", "operateAccessibilityEvent");
if (step == STEP_REQUEST_DEVICE_ADMIN) {
if (event.getClassName() != null) {
......@@ -118,15 +127,16 @@ public abstract class BaseAutoGetPermission {
}
if (step == STEP_REQUEST_AUTO_STARTUP) {
if (event.getClassName() != null) {
if (event.getSource() == null)
return;
if (PermissionUtil.checkAutoStartUp(getApplicationContext())) {
Log.i("reqeustAutoStartUp", "已经有了自启动");
resetStep();
} else {
reqeustAutoStartUp(event);
}
......@@ -143,9 +153,10 @@ public abstract class BaseAutoGetPermission {
if (event.getSource() != null) {
if (PermissionUtil.checkBatteryOptimize(getApplicationContext())) {
Log.i("reqeustAutoStartUp", "已经忽略电量优化");
resetStep();
} else {
Log.i("reqeustAutoStartUp", "没有忽略电量优化");
requestBatteryOptimize(event);
}
}
......@@ -156,8 +167,10 @@ public abstract class BaseAutoGetPermission {
if (event.getClassName() != null) {
if (event.getSource() != null) {
if (PermissionUtil.checkAppUsagePermission(getApplicationContext())) {
Log.i("reqeustAutoStartUp", "已经有了用户使用权限");
resetStep();
} else {
Log.i("reqeustAutoStartUp", "没有了用户使用权限");
requestUsageAppPermission(event);
}
}
......@@ -211,7 +224,6 @@ public abstract class BaseAutoGetPermission {
}
if (!PermissionUtil.checkDeviceAdminPermission(getApplicationContext())) {
......@@ -397,12 +409,24 @@ public abstract class BaseAutoGetPermission {
}
public void showToastLong(String msg) {
handler.post(new Runnable() {
@Override
public void run() {
Logger.e(TAG, "showToastLong\t" + msg);
toast.setText("倍知守护提醒您 : \n" + msg);
toast.setText(msg);
toast.show();
}
});
}
public void showToastLongTow(String msg) {
handler.post(new Runnable() {
@Override
public void run() {
Logger.e(TAG, "showToastLong\t" + msg);
toast.setText(msg);
toast.show();
}
});
......
......@@ -8,6 +8,7 @@ import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.util.Logger;
import com.android.launcher3.util.PermissionUtil;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
......@@ -31,11 +32,17 @@ public class SamsungAutoPermissionGetter extends BaseAutoGetPermission {
if ("com.android.settings.Settings$DeviceAdminSettingsActivity".equals(event.getClassName().toString())) {
// 已跳转到设备管理器页面
sleepShort();
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, appName);
if (!performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
if (accessibilityNodeInfo1 != null) {
if (!performAction(accessibilityNodeInfo1.getParent(), AccessibilityNodeInfo.ACTION_CLICK))
showToastLong("请找到【" + appName + "】应用并点击");
} else {
showToastLong("请找到【" + appName + "】应用并点击");
}
return;
} else {
sleepShort();
......@@ -57,6 +64,7 @@ public class SamsungAutoPermissionGetter extends BaseAutoGetPermission {
return;
}
showToastLong("请点击【启用/激活此设备管理员】");
PermissionUtil.isAdminDevice = true;
return;
}
}
......
package com.android.launcher3.debug;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import com.android.launcher3.R;
/**
* Author: roczheng
* Date: 2019/11/28
* Time: 14:10
* Description:
*/
public class CustomDialog extends AlertDialog {
private Context mContext;
private int mResource;
private View mDialogView;
public CustomDialog(Context context, int resource) {
super(context, R.style.Theme_AppCompat_Dialog);//加载dialog的样式
this.mContext = context;
this.mResource = resource;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//6.0
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
}else {
getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
}
} else {
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
}
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
if (mDialogView != null) {
setContentView(mDialogView);
} else if (mResource != 0) {
mDialogView = LayoutInflater.from(mContext).inflate(mResource, null);
setContentView(mDialogView, layoutParams);
}
setCanceledOnTouchOutside(false);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
}
......@@ -78,6 +78,9 @@ public class DebugInfoActivity extends BaseActivity implements View.OnClickListe
rv_app_manage_info.setLayoutManager(new LinearLayoutManager(this));
rv_app_manage_info.setAdapter(timeAdapter);
//TimeModeManager.getInstance(getApplicationContext()).setCurrentWorkModel(ColumnDef.TimeManager.WEEK_RESET);
//LauncherManager.getInstance().lockScreenNormal(getApplicationContext());
loadWorkMode();
loadAppInfo();
update();
......
package com.android.launcher3.debug;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.android.launcher3.R;
import com.android.launcher3.manager.LauncherManager;
public class ProgressActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("service_zzzzzzzzzzzz", "ProgressActivity监听");
setContentView(R.layout.activity_clock_alarm);
}
}
......@@ -22,14 +22,18 @@ public class Constants {
// 应用使用时长上限
public static final int DIALOG_TYPE_APP_USE_DEADLINE = 3;
// 金币不足
// 金币不足
public static final int DIALOG_TYPE_MONEY_NOT_ENOUGH = 4;
// 某个分类下的分类总时长已使用完毕
// 某个分类下的分类总时长已使用完毕
public static final int DIALOG_TYPE_SOME_CLASS_TIME_OUT = 5;
public static final String[] SAFE_APP = {"com.samsung.android.dialer|com.android.dialer|com.samsung.android.contacts|com.android.contacts", "com.samsung.android.messaging|com.android.mms", "com.sec.android.app.camera|com.android.camera2|com.meizu.media.camera|com.huawei.camera"};
//忽略规则的应用
public static final String[] SAFE_APP = {"com.samsung.android.dialer|com.android.dialer|com.samsung.android.contacts|com.android.contacts",
"com.samsung.android.messaging|com.android.mms",
"com.sec.android.app.camera|com.android.camera2|com.meizu.media.camera|com.huawei.camera",
"com.huawei.android.internal.app"};
//系统应用
public static final String[] SYSTEM_APP = {"com.android.systemui", "com.samsung.android.packageinstaller|com.android.packageinstaller", "com.samsung.android.incallui|com.android.incallui"};
......
package com.android.launcher3.manager;
import android.app.Activity;
import android.app.Application;
import android.content.ComponentName;
import android.content.ContentProviderOperation;
......@@ -13,7 +14,9 @@ import android.database.Cursor;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.ArrayMap;
......@@ -27,6 +30,7 @@ import com.android.launcher3.LockScreenActivity;
import com.android.launcher3.LockScreenInterface;
import com.android.launcher3.accessibility.FloatWindowService;
import com.android.launcher3.accessibility.ListenerAppService;
import com.android.launcher3.debug.CustomDialog;
import com.android.launcher3.debug.DebugInfoActivity;
import com.android.launcher3.debug.SearchAppCanUseActivity;
import com.android.launcher3.model.ConfigManager;
......@@ -80,6 +84,9 @@ public class LauncherManager {
private static Context mContext;
public static CustomDialog mCustomDialog;
public static int mStartSendCount = 0;
private final LauncherProvider.ChangeListenerWrapper mListenerWrapper = new LauncherProvider.ChangeListenerWrapper();
private Handler mListenerHandler;
......@@ -111,6 +118,7 @@ public class LauncherManager {
/**
* 设置Debug模式 正式版需关闭
*
* @param debugModel
*/
public static void setDebugModel(boolean debugModel) {
......@@ -153,6 +161,15 @@ public class LauncherManager {
private LauncherManager() {
appInfo = new ArrayMap<>();
/* ManagementInfo managementInfo = new ManagementInfo();
managementInfo.setUseEndTimeStamp(43320);
managementInfo.setPackageName("com.tencent.mobileqq");
managementInfo.setLock(ColumnDef.LockApp.LOCKED);
managementInfo.setUseType(ColumnDef.AppUseType.GAME_LOCK_TYPE);
LauncherManager.getInstance().addPackageInfo(managementInfo);
*/
timeModeManager = TimeModeManager.getInstance(getContext());
mListenerHandler = new Handler(mListenerWrapper);
......@@ -288,9 +305,10 @@ public class LauncherManager {
/**
* 状态更新发广播给桌面(Launcher)处理
*
* @param packageName
*/
private void refreshLauncherIconWidget(String packageName) {
public void refreshLauncherIconWidget(String packageName) {
Intent intent = new Intent(Constants.ACTION_UPDATE_ICON);
intent.putExtra(Constants.EXTRA_PACKAGE, packageName);
......@@ -519,6 +537,7 @@ public class LauncherManager {
return appInfo;
}
public void backLauncherHome(Context context) {
UIExecutor.postRunable(new Runnable() {
@Override
......@@ -529,7 +548,6 @@ public class LauncherManager {
context.startActivity(home);
}
});
}
......@@ -667,6 +685,11 @@ public class LauncherManager {
}
/**
* 是否强制锁屏
*
* @return
*/
public boolean isForceLock() {
return lockScreenMode == ColumnDef.LockScreen.MODE_FORCE_LOCK || lockScreenMode == ColumnDef.LockScreen.MODE_REST;
}
......@@ -873,20 +896,22 @@ public class LauncherManager {
/**
* 跳转debug信息页面
*
* @param context
*/
public void jumpDebugInfo(Context context){
Intent intent=new Intent(context, DebugInfoActivity.class);
public void jumpDebugInfo(Context context) {
Intent intent = new Intent(context, DebugInfoActivity.class);
context.startActivity(intent);
}
/**
* 跳转查询app是否可用页面
*
* @param context
*/
public void jumpSearchAppCanUse(Context context){
Intent intent=new Intent(context, SearchAppCanUseActivity.class);
public void jumpSearchAppCanUse(Context context) {
Intent intent = new Intent(context, SearchAppCanUseActivity.class);
context.startActivity(intent);
}
}
......@@ -280,6 +280,8 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan
if (componentName.getPackageName().equals(mLauncher.getPackageName())) {
boolean enable = LauncherManager.getInstance().getUninstallEnable();
Logger.e("uninstallDisableApp", enable + "");
//是否拦截系统设置
LauncherManager.getInstance().setInterceptSystemSetting(!enable);
return enable;
}
......
......@@ -20,6 +20,7 @@ import android.content.ComponentName;
import android.os.Handler;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
......@@ -47,7 +48,8 @@ import java.util.List;
public class PopupPopulator {
public static final int MAX_SHORTCUTS = 4;
@VisibleForTesting static final int NUM_DYNAMIC = 2;
@VisibleForTesting
static final int NUM_DYNAMIC = 2;
public static final int MAX_SHORTCUTS_IF_NOTIFICATIONS = 2;
/**
......@@ -138,9 +140,14 @@ public class PopupPopulator {
}
uiHandler.post(() -> container.applyNotificationInfos(infos));
}
List<ShortcutInfoCompat> shortcuts = DeepShortcutManager.getInstance(launcher)
List<ShortcutInfoCompat> shortcuts = new ArrayList<>();
try {
shortcuts = DeepShortcutManager.getInstance(launcher)
.queryForShortcutsContainer(activity, shortcutIds, user);
} catch (Exception e) {
e.printStackTrace();
}
String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null
: notificationKeys.get(0).shortcutId;
shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe);
......
......@@ -81,7 +81,7 @@ public class DeepShortcutManager {
/**
* Queries for the shortcuts with the package name and provided ids.
*
* <p>
* This method is intended to get the full details for shortcuts when they are added or updated,
* because we only get "key" fields in onShortcutsChanged().
*/
......@@ -115,7 +115,7 @@ public class DeepShortcutManager {
try {
mLauncherApps.pinShortcuts(packageName, pinnedIds, user);
mWasLastCallSuccess = true;
} catch (SecurityException|IllegalStateException e) {
} catch (SecurityException | IllegalStateException e) {
Log.w(TAG, "Failed to unpin shortcut", e);
mWasLastCallSuccess = false;
}
......@@ -137,7 +137,7 @@ public class DeepShortcutManager {
try {
mLauncherApps.pinShortcuts(packageName, pinnedIds, user);
mWasLastCallSuccess = true;
} catch (SecurityException|IllegalStateException e) {
} catch (SecurityException | IllegalStateException e) {
Log.w(TAG, "Failed to pin shortcut", e);
mWasLastCallSuccess = false;
}
......@@ -152,7 +152,7 @@ public class DeepShortcutManager {
mLauncherApps.startShortcut(packageName, id, sourceBounds,
startActivityOptions, user);
mWasLastCallSuccess = true;
} catch (SecurityException|IllegalStateException e) {
} catch (SecurityException | IllegalStateException e) {
Log.e(TAG, "Failed to start shortcut", e);
mWasLastCallSuccess = false;
}
......@@ -167,7 +167,7 @@ public class DeepShortcutManager {
shortcutInfo.getShortcutInfo(), density);
mWasLastCallSuccess = true;
return icon;
} catch (SecurityException|IllegalStateException e) {
} catch (SecurityException | IllegalStateException e) {
Log.e(TAG, "Failed to get shortcut icon", e);
mWasLastCallSuccess = false;
}
......@@ -177,7 +177,7 @@ public class DeepShortcutManager {
/**
* Returns the id's of pinned shortcuts associated with the given package and user.
*
* <p>
* If packageName is null, returns all pinned shortcuts regardless of package.
*/
public List<ShortcutInfoCompat> queryForPinnedShortcuts(String packageName, UserHandle user) {
......@@ -204,12 +204,13 @@ public class DeepShortcutManager {
/**
* Query the system server for all the shortcuts matching the given parameters.
* If packageName == null, we query for all shortcuts with the passed flags, regardless of app.
*
* <p>
* TODO: Use the cache to optimize this so we don't make an RPC every time.
*/
@TargetApi(25)
private List<ShortcutInfoCompat> query(int flags, String packageName,
ComponentName activity, List<String> shortcutIds, UserHandle user) {
try {
if (Utilities.ATLEAST_NOUGAT_MR1) {
ShortcutQuery q = new ShortcutQuery();
q.setQueryFlags(flags);
......@@ -222,7 +223,8 @@ public class DeepShortcutManager {
try {
shortcutInfos = mLauncherApps.getShortcuts(q, user);
mWasLastCallSuccess = true;
} catch (SecurityException|IllegalStateException e) {
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Failed to query for shortcuts", e);
mWasLastCallSuccess = false;
}
......@@ -237,6 +239,10 @@ public class DeepShortcutManager {
} else {
return Collections.EMPTY_LIST;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@TargetApi(25)
......@@ -244,7 +250,7 @@ public class DeepShortcutManager {
if (Utilities.ATLEAST_NOUGAT_MR1) {
try {
return mLauncherApps.hasShortcutHostPermission();
} catch (SecurityException|IllegalStateException e) {
} catch (SecurityException | IllegalStateException e) {
Log.e(TAG, "Failed to make shortcut manager call", e);
}
}
......
......@@ -91,7 +91,6 @@ public class ItemClickHandler {
ShortcutInfo shortcutInfo = (ShortcutInfo) tag;
String packageName = shortcutInfo.getIntent().getComponent().getPackageName();
if (packageName.equals(v.getContext().getPackageName())) {
onClickAppShortcut(v, (ShortcutInfo) tag, launcher);
return;
......@@ -108,7 +107,6 @@ public class ItemClickHandler {
LauncherManager.getInstance().backLauncherHome(v.getContext(), Constants.DIALOG_TYPE_APP_UNCLASS);
return;
} else {
int type = LauncherManager.getInstance().canUse(packageName);
if (type < 0) {
switch (type) {
......@@ -125,6 +123,11 @@ public class ItemClickHandler {
}
}
} else {
/*if (packageName.equals(v.getContext().getPackageName())){
LauncherManager.getInstance().backLauncherHome(v.getContext(), Constants.DIALOG_TYPE_APP_USE_DEADLINE);
}else {
LauncherManager.getInstance().backLauncherHome(v.getContext(), Constants.DIALOG_TYPE_APP_UNCLASS);
}*/
LauncherManager.getInstance().backLauncherHome(v.getContext(), Constants.DIALOG_TYPE_APP_UNCLASS);
return;
}
......
......@@ -70,7 +70,10 @@ public class KToast {
mView.findViewById(R.id.tv_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
if (mView.getParent() != null) {
windowManager.removeView(mView);
isShowing = false;
}
}
});
mView.findViewById(R.id.tv_help).setOnClickListener(new View.OnClickListener() {
......@@ -84,7 +87,6 @@ public class KToast {
context.startActivity(intent);
}
});
}
public void setText(String msg) {
......
......@@ -6,6 +6,7 @@ import android.text.TextUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
public class SystemUtils {
......@@ -21,7 +22,7 @@ public class SystemUtils {
* @return
*/
public static boolean isMIUI() {
return getDeviceBrand().toUpperCase().equals("XIAOMI")||getDeviceBrand().toUpperCase().equals("MEITU");
return getDeviceBrand().toUpperCase().equals("XIAOMI") || getDeviceBrand().toUpperCase().equals("MEITU");
}
......@@ -75,10 +76,15 @@ public class SystemUtils {
return getDeviceBrand().toUpperCase().equals("SAMSUNG");
}
public static boolean isNOKIA(){
public static boolean isNOKIA() {
return getDeviceBrand().toUpperCase().equals("NOKIA");
}
/**
* 获取MIUI版本
*
* @return
*/
public static String getMIUIVersion() {
String versionCode = "";
String manufacturer = Build.MANUFACTURER;
......@@ -89,6 +95,24 @@ public class SystemUtils {
return versionCode;
}
/**
* 获取EMUI版本
*
* @return
*/
public static String getEMUI() {
Class<?> classType = null;
String buildVersion = null;
try {
classType = Class.forName("android.os.SystemProperties");
Method getMethod = classType.getDeclaredMethod("get", new Class<?>[]{String.class});
buildVersion = (String) getMethod.invoke(classType, new Object[]{"ro.build.version.emui"});
} catch (Exception e) {
e.printStackTrace();
}
return buildVersion;
}
public static String getSystemProperty(String propName) {
String line;
BufferedReader input = null;
......
package com.android.launcher3.util;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import com.android.launcher3.Launcher;
import com.android.launcher3.manager.LauncherManager;
public class UIExecutor {
private static Handler uiHandler = new Handler(Looper.getMainLooper());
public static Handler uiHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
if (msg.what == 200) {
Intent home = new Intent(LauncherManager.getContext(), Launcher.class);
home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
home.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
LauncherManager.getContext().startActivity(home);
}
}
};
public static void postRunable(Runnable runnable) {
......@@ -13,8 +28,8 @@ public class UIExecutor {
// Looper.prepare();
}
public static void postRunableDelay(Runnable runnable,long millsTime) {
uiHandler.postDelayed(runnable,millsTime);
public static void postRunableDelay(Runnable runnable, long millsTime) {
uiHandler.postDelayed(runnable, millsTime);
// Looper.prepare();
}
}
......@@ -266,7 +266,7 @@ public class WallpaperOffsetInterpolator extends BroadcastReceiver {
private void setOffsetSafely(IBinder token) {
try {
mWM.setWallpaperOffsets(token, mCurrentOffset, 0.5f);
} catch (IllegalArgumentException e) {
} catch (Exception e) {
Log.e(TAG, "Error updating wallpaper offset: " + e);
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp"
android:color="@color/color_white"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/pb_loading"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -6,51 +6,80 @@
android:background="@drawable/shape_toast_back"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="6dp"
android:layout_marginBottom="10dp"
android:text="倍知守护提醒您:"
android:textColor="@android:color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_close"
android:id="@+id/tv_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingTop="4dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="4dp"
android:text="关闭"
android:paddingBottom="10dp"
android:textColor="@android:color/white"
android:textSize="16sp"></TextView>
android:textSize="16sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_help"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/button_bg_drawable_shape"
android:paddingLeft="10dp"
android:paddingTop="4dp"
android:paddingRight="10dp"
android:paddingBottom="4dp"
android:text="没有自动获取权限?(帮助)"
android:text="关闭提示"
android:textColor="@android:color/white"
android:textSize="16sp"></TextView>
android:textSize="16sp" />
</RelativeLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_msg"
android:id="@+id/tv_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/button_bg_drawable_shape"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingTop="4dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:paddingBottom="4dp"
android:text="点此获取帮助"
android:textColor="@android:color/white"
android:textSize="16sp"></TextView>
android:textSize="16sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -88,7 +88,7 @@
<string name="title_missing_notification_access" msgid="7503287056163941064">"需要获取通知使用权"</string>
<string name="msg_missing_notification_access" msgid="281113995110910548">"要显示通知圆点,请开启<xliff:g id="NAME">%1$s</xliff:g>的应用通知功能"</string>
<string name="title_change_settings" msgid="1376365968844349552">"更改设置"</string>
<string name="icon_badging_service_title" msgid="2309733118428242174">dankal_launcher</string>
<string name="icon_badging_service_title" msgid="2309733118428242174">倍知守护孩子端</string>
<string name="auto_add_shortcuts_label" msgid="8222286205987725611">"将图标添加到主屏幕"</string>
<string name="auto_add_shortcuts_description" msgid="7117251166066978730">"适用于新应用"</string>
<string name="icon_shape_override_label" msgid="2977264953998281004">"更改图标形状"</string>
......
......@@ -88,7 +88,7 @@
<string name="title_missing_notification_access" msgid="7503287056163941064">"需要獲取通知存取權"</string>
<string name="msg_missing_notification_access" msgid="281113995110910548">"如要顯示「通知圓點」,請開啟「<xliff:g id="NAME">%1$s</xliff:g>」的應用程式通知功能"</string>
<string name="title_change_settings" msgid="1376365968844349552">"變更設定"</string>
<string name="icon_badging_service_title" msgid="2309733118428242174">dankal_launcher</string>
<string name="icon_badging_service_title" msgid="2309733118428242174">倍知守护孩子端</string>
<string name="auto_add_shortcuts_label" msgid="8222286205987725611">"將圖示加到主畫面"</string>
<string name="auto_add_shortcuts_description" msgid="7117251166066978730">"適用於新安裝的應用程式"</string>
<string name="icon_shape_override_label" msgid="2977264953998281004">"變更圖示形狀"</string>
......
......@@ -25,7 +25,7 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug{
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
......
......@@ -3,9 +3,12 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.dankal.dankal_launcher">
<uses-permission
android:name="android.permission.SET_ACTIVITY_WATCHER"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".MyApplication"
android:backupAgent="com.android.launcher3.LauncherBackupAgent"
android:debuggable="true"
......@@ -18,33 +21,43 @@
android:restoreAnyVersion="true"
android:supportsRtl="true"
android:theme="@style/LauncherTheme"
tools:replace="android:icon">
tools:replace="android:icon"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".PermissionSettingActivity"></activity>
<!--
Main launcher activity. When extending only change the name, and keep all the
attributes and intent filters the same
-->
<!--
The settings activity. When extending keep the intent filter present
-->
<!-- The settings activity. When extending keep the intent filter present -->
<activity
android:name=".PackageManageActivity"
android:autoRemoveFromRecents="true"
android:theme="@android:style/Theme.DeviceDefault.Settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- <activity-alias
android:name=".NewActivity1"
android:enabled="true"
android:label="Alias1"
android:icon="@mipmap/ic_launcher_round"
android:targetActivity=".PackageManageActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>-->
<activity
android:name=".SetActivity"
android:exported="true">
</activity>
android:exported="true"></activity>
<service
android:name="com.android.launcher3.accessibility.PermissionOpenAccessiblityService"
......@@ -58,17 +71,7 @@
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
</service>
<!--
The settings provider contains Home's data, like the workspace favorites. The permissions
should be changed to what is defined above. The authorities should also be changed to
represent the package name.
-->
</application>
</manifest>
\ No newline at end of file
package com.dankal.dankal_launcher;
import android.app.Activity;
import android.app.Application;
import com.android.launcher3.manager.LauncherManager;
......
package com.dankal.dankal_launcher;
import android.app.Activity;
import android.app.admin.DeviceAdminService;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import androidx.core.view.accessibility.AccessibilityViewCommand;
public class PermissionUtils {
}
package com.dankal.dankal_launcher;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityManager;
import com.android.launcher3.util.PermissionUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Author: roczheng
* Date: 2020/5/31
* Time: 15:26
* Description:
*/
public class WindowPermissionCheck {
public static boolean checkPermission(Activity activity) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
// && !Settings.canDrawOverlays(activity)) {
// return false;
// }
return PermissionUtil.checkFloatPermission(activity);
}
public static void openPermission(Activity activity) {
activity.startActivityForResult(
new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + activity.getPackageName())), 0);
}
public static void onActivityResult(Activity activity,
int requestCode,
int resultCode,
Intent data,
OnWindowPermissionListener onWindowPermissionListener) {
if (requestCode == 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& !Settings.canDrawOverlays(activity)) {
// Toast.makeText(activity.getApplicationContext(), "授权失败", Toast.LENGTH_SHORT).show();
if (onWindowPermissionListener != null)
onWindowPermissionListener.onFailure();
} else {
// Toast.makeText(activity.getApplicationContext(), "授权成功", Toast.LENGTH_SHORT).show();
if (onWindowPermissionListener != null)
onWindowPermissionListener.onSuccess();
}
}
}
public static boolean isServiceON(Context context, String className) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo>
runningServices = activityManager.getRunningServices(100);
if (runningServices.size() < 0) {
return false;
}
for (int i = 0; i < runningServices.size(); i++) {
ComponentName service = runningServices.get(i).service;
if (service.getClassName().contains(className)) {
return true;
}
}
return false;
}
/** 查看服务是否开启*/
public static Boolean isServiceRunning(Context context, String serviceName) {
//获取服务方法 参数 必须用大写的Context!!!
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> infos = am.getRunningServices(100);
for (ActivityManager.RunningServiceInfo info : infos) {
String className = info.service.getClassName();
if(serviceName.equals(className))
return true;
}
return false;
}
public static boolean isAccessibilityEnabled(Context context) throws RuntimeException {
if (context == null) {
return false;
}
// 检查AccessibilityService是否开启
AccessibilityManager am = (AccessibilityManager) context.getSystemService(android.content.Context.ACCESSIBILITY_SERVICE);
boolean isAccessibilityEnabled_flag = am.isEnabled();
boolean isExploreByTouchEnabled_flag = false;
// 检查无障碍服务是否以语音播报的方式开启
isExploreByTouchEnabled_flag = isScreenReaderActive(context);
return (isAccessibilityEnabled_flag && isExploreByTouchEnabled_flag);
}
private final static String SCREEN_READER_INTENT_ACTION = "android.accessibilityservice.AccessibilityService";
private final static String SCREEN_READER_INTENT_CATEGORY = "android.accessibilityservice.category.FEEDBACK_SPOKEN";
private static boolean isScreenReaderActive(Context context) {
// 通过Intent方式判断是否存在以语音播报方式提供服务的Service,还需要判断开启状态
Intent screenReaderIntent = new Intent(SCREEN_READER_INTENT_ACTION);
screenReaderIntent.addCategory(SCREEN_READER_INTENT_CATEGORY);
List<ResolveInfo> screenReaders = context.getPackageManager().queryIntentServices(screenReaderIntent, 0);
// 如果没有,返回false
if (screenReaders == null || screenReaders.size() <= 0) {
return false;
}
boolean hasActiveScreenReader = false;
if (Build.VERSION.SDK_INT <= 15) {
ContentResolver cr = context.getContentResolver();
Cursor cursor = null;
int status = 0;
for (ResolveInfo screenReader : screenReaders) {
cursor = cr.query(Uri.parse("content://" + screenReader.serviceInfo.packageName
+ ".providers.StatusProvider"), null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
status = cursor.getInt(0);
cursor.close();
// 状态1为开启状态,直接返回true即可
if (status == 1) {
return true;
}
}
}
} else if (Build.VERSION.SDK_INT >= 26) {
// 高版本可以直接判断服务是否处于开启状态
for (ResolveInfo screenReader : screenReaders) {
hasActiveScreenReader |= isAccessibilitySettingsOn(context, screenReader.serviceInfo.packageName + "/" + screenReader.serviceInfo.name);
}
} else {
// 判断正在运行的Service里有没有上述存在的Service
List<String> runningServices = new ArrayList<String>();
android.app.ActivityManager manager = (android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (android.app.ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
runningServices.add(service.service.getPackageName());
}
for (ResolveInfo screenReader : screenReaders) {
if (runningServices.contains(screenReader.serviceInfo.packageName)) {
hasActiveScreenReader |= true;
}
}
}
return hasActiveScreenReader;
}
// To check if service is enabled
private static boolean isAccessibilitySettingsOn(Context context, String service) {
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
String settingValue = Settings.Secure.getString(
context.getApplicationContext().getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
if (settingValue != null) {
mStringColonSplitter.setString(settingValue);
while (mStringColonSplitter.hasNext()) {
String accessibilityService = mStringColonSplitter.next();
if (accessibilityService.equalsIgnoreCase(service)) {
return true;
}
}
}
return false;
}
public interface OnWindowPermissionListener {
void onSuccess();
void onFailure();
}
}
......@@ -40,4 +40,48 @@
android:layout_height="wrap_content"
android:text="跳转设置"
android:textSize="22sp"></TextView>
<TextView
android:id="@+id/tv_is_uninstall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="设置可卸载"/>
<TextView
android:id="@+id/tv_floating_window"
android:layout_width="match_parent"
android:text="判断是否有悬浮窗权限"
android:textSize="22sp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="步骤1,显示在其他应用上层"/>
<TextView
android:id="@+id/tv_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="步骤2,打开无障碍"/>
<TextView
android:id="@+id/tv_permission"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="步骤3,,跳转权限页面"/>
<TextView
android:id="@+id/tv_change_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="切换图标"/>
</LinearLayout>
\ No newline at end of file
......@@ -3,4 +3,9 @@
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="colorFF">#FFFFFF</color>
<color name="col_97">#FF979797</color>
</resources>
<resources>
<string name="app_name">dankal_launcher</string>
<string name="app_name">倍知守护孩子端</string>
</resources>
<resources>
<style name="text_col97_size16" parent="text_col97">
<item name="android:textSize">16sp</item>
</style>
<style name="text_col97" parent="ww_hw">
<item name="android:textColor">@color/col_97</item>
</style>
<style name="ww_hw">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment