version:1.5

fix:迁移到奥乐云平台
add:
This commit is contained in:
2021-12-10 14:49:23 +08:00
parent 2462bafa85
commit ed8310da47
713 changed files with 6024 additions and 4805 deletions

View File

@@ -0,0 +1,462 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aoleyun.os.touch;
import static com.aoleyun.os.ItemInfoWithIcon.FLAG_DISABLED_BY_PUBLISHER;
import static com.aoleyun.os.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER;
import static com.aoleyun.os.ItemInfoWithIcon.FLAG_DISABLED_QUIET_USER;
import static com.aoleyun.os.ItemInfoWithIcon.FLAG_DISABLED_SAFEMODE;
import static com.aoleyun.os.ItemInfoWithIcon.FLAG_DISABLED_SUSPENDED;
import static com.aoleyun.os.model.AppLaunchTracker.CONTAINER_ALL_APPS;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Process;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.aoleyun.os.AppInfo;
import com.aoleyun.os.BubbleTextView;
import com.aoleyun.os.FolderInfo;
import com.aoleyun.os.ItemInfo;
import com.aoleyun.os.Launcher;
import com.aoleyun.os.LauncherAppWidgetInfo;
import com.aoleyun.os.LauncherAppWidgetProviderInfo;
import com.aoleyun.os.TTUtils.CustomDialog;
import com.aoleyun.os.TTUtils.ToastUtil;
import com.aoleyun.os.base.MyApplication;
import com.aoleyun.os.PromiseAppInfo;
import com.aoleyun.os.R;
import com.aoleyun.os.Statistics.AppInformation;
import com.aoleyun.os.Statistics.StatisticsInfo;
import com.aoleyun.os.TTUtils.APKUtils;
import com.aoleyun.os.TTUtils.Utils;
import com.aoleyun.os.WorkspaceItemInfo;
import com.aoleyun.os.compat.AppWidgetManagerCompat;
import com.aoleyun.os.folder.Folder;
import com.aoleyun.os.folder.FolderIcon;
import com.aoleyun.os.network.AppPasswdBean;
import com.aoleyun.os.network.BaseResponse;
import com.aoleyun.os.network.NetWorkManager;
import com.aoleyun.os.network.api.AddAppLog;
import com.aoleyun.os.testing.TestProtocol;
import com.aoleyun.os.util.PackageManagerHelper;
import com.aoleyun.os.views.FloatingIconView;
import com.aoleyun.os.widget.PendingAppWidgetHostView;
import com.aoleyun.os.widget.WidgetAddFlowHandler;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tencent.mmkv.MMKV;
import org.json.JSONArray;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
/**
* Class for handling clicks on workspace and all-apps items
*/
public class ItemClickHandler {
/**
* Instance used for click handling on items
*/
public static final OnClickListener INSTANCE = getInstance(null);
public static final OnClickListener getInstance(String sourceContainer) {
return v -> onClick(v, sourceContainer);
}
private static void onClick(View v, String sourceContainer) {
if (TestProtocol.sDebugTracing) {
android.util.Log.d(TestProtocol.NO_START_TAG,
"onClick 1");
}
// Make sure that rogue clicks don't get through while allapps is launching, or after the
// view has detached (it's possible for this to happen if the view is removed mid touch).
if (v.getWindowToken() == null) {
if (TestProtocol.sDebugTracing) {
android.util.Log.d(TestProtocol.NO_START_TAG,
"onClick 2");
}
return;
}
Launcher launcher = Launcher.getLauncher(v.getContext());
if (!launcher.getWorkspace().isFinishedSwitchingState()) {
if (TestProtocol.sDebugTracing) {
android.util.Log.d(TestProtocol.NO_START_TAG,
"onClick 3");
}
return;
}
Object tag = v.getTag();
if (tag instanceof WorkspaceItemInfo) {
String ApplicationLock = MMKV.defaultMMKV().decodeString("ApplicationLock");
Log.e("onClick", "onClick: " + ApplicationLock);
Type type = new TypeToken<List<AppPasswdBean>>() {
}.getType();
Gson gson = new Gson();
List<AppPasswdBean> appPasswdBeans = gson.fromJson(ApplicationLock, type);
String packageName = ((WorkspaceItemInfo) tag).getTargetComponent().getPackageName();
Log.e("ItemClickHandler", "onClick: " + packageName);
if (appPasswdBeans == null) {
onClickAppShortcut(v, (WorkspaceItemInfo) tag, launcher, sourceContainer);
} else {
HashMap<String, String> hashMap = new HashMap<>();
for (AppPasswdBean bean : appPasswdBeans) {
hashMap.put(bean.getApp_package(), bean.getPassword());
}
if (hashMap.get(packageName) != null) {
CustomDialog dialog = new CustomDialog(v.getContext());
dialog.setTitle("请输入密码");
// dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.setOnClickBottomListener(new CustomDialog.OnClickBottomListener() {
@Override
public void onPositiveClick() {
if (hashMap.get(packageName).equals(dialog.messageTv.getText().toString())) {
onClickAppShortcut(v, (WorkspaceItemInfo) tag, launcher, sourceContainer);
dialog.dismiss();
}else {
ToastUtil.showCenter("密码错误");
}
}
@Override
public void onNegtiveClick() {
dialog.dismiss();
}
});
dialog.show();
dialog.getWindow().setGravity(Gravity.CENTER);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} else {
onClickAppShortcut(v, (WorkspaceItemInfo) tag, launcher, sourceContainer);
}
}
// Log.e("ItemClickHandler", "onClick: " + packageName);
// if (cameraClosed(v.getContext(), packageName)) {
// return;
// }
// onClickAppShortcut(v, (WorkspaceItemInfo) tag, launcher, sourceContainer);
// AppInformation app = null;
// try {
// app = getInfoFromPackageName(packageName);
// } catch (Exception e) {
// Log.e("onClick", e.getMessage());
// }
// if (app != null) {
// Log.e("fht", "运行时间: " + DateUtils.formatElapsedTime(app.getUsedTimebyDay() / 1000));
// Log.e("fht", "运行时间: " + app.getUsedTimebyDay() / 1000);
// MyApplication.getInstance().setTime(app.getUsedTimebyDay() / 1000);
//
// } else {
// Log.e("fht", "首次运行:" + "包名:" + packageName);
// MyApplication.getInstance().setTime(0);
//
// }
// if (!APKUtils.isSystemApp(v.getContext(), packageName) && !Arrays.asList(packages).contains(packageName)) {
//// HTTPInterface.sendTimeLog(handler, userInfo, ((ShortcutInfo) tag).title.toString(), 1, 0);
// SendOpenApp(packageName);
// }
// //写入正在运行的app的包名和时间
// MyApplication.getInstance().setAppPackageName(packageName);
// MyApplication.getInstance().setOnClickTime(System.currentTimeMillis());
} else if (tag instanceof FolderInfo) {
if (v instanceof FolderIcon) {
onClickFolderIcon(v);
}
} else if (tag instanceof AppInfo) {
if (TestProtocol.sDebugTracing) {
android.util.Log.d(TestProtocol.NO_START_TAG,
"onClick 4");
}
startAppShortcutOrInfoActivity(v, (AppInfo) tag, launcher,
sourceContainer == null ? CONTAINER_ALL_APPS : sourceContainer);
} else if (tag instanceof LauncherAppWidgetInfo) {
if (v instanceof PendingAppWidgetHostView) {
onClickPendingWidget((PendingAppWidgetHostView) v, launcher);
}
}
}
private static boolean cameraClosed(Context context, String pkg) {
if ("com.mediatek.camera".equalsIgnoreCase(pkg)) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_camera", 0) == 1) {
Toast.makeText(context, "摄像头已禁止使用", Toast.LENGTH_SHORT).show();
return true;
} else {
return false;
}
} else {
return false;
}
}
public static String[] packages = {
"com.appstore.uiui",
"com.uiuios.updatetools",
"com.info.sn",
"com.android.uiuios",
"com.easyold.uiuios",
"com.jiaoguanyi.store"
};
public static AppInformation getInfoFromPackageName(String packageName) {
List<AppInformation> list;
AppInformation app = null;
StatisticsInfo statisticsInfo = new StatisticsInfo(MyApplication.getInstance().getApplicationContext());
list = statisticsInfo.getShowList();
for (AppInformation appInformation : list) {
String name = appInformation.getPackageName();
if (appInformation.getPackageName().equals(packageName)) {
return appInformation;
}
}
return app;
}
private static void SendOpenApp(String packageName) {
PackageManager pm = MyApplication.getInstance().getPackageManager();
PackageInfo appInfo = null;
try {
appInfo = pm.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (null != appInfo) {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = appInfo.getLongVersionCode();
} else {
appVersionCode = appInfo.versionCode;
}
AddAppLog appLog = NetWorkManager.getInstance().getapplogControl();
String sn = Utils.getSerial();
appLog.addLog(sn, packageName, appVersionCode, System.currentTimeMillis() / 1000, 1)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(BaseResponse baseResponse) {
int code = baseResponse.code;
if (code == 200) {
Log.e("SendOpenApp", "onNext: " + code + baseResponse.data);
} else {
Log.e("SendOpenApp", "onNext: " + code + baseResponse.msg);
}
}
@Override
public void onError(Throwable e) {
Log.e("SendOpenApp", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
}
/**
* Event handler for a folder icon click.
*
* @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
*/
private static void onClickFolderIcon(View v) {
Folder folder = ((FolderIcon) v).getFolder();
if (!folder.isOpen() && !folder.isDestroyed()) {
// Open the requested folder
folder.animateOpen();
}
}
/**
* Event handler for the app widget view which has not fully restored.
*/
private static void onClickPendingWidget(PendingAppWidgetHostView v, Launcher launcher) {
if (launcher.getPackageManager().isSafeMode()) {
Toast.makeText(launcher, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
return;
}
final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
if (v.isReadyForClickSetup()) {
LauncherAppWidgetProviderInfo appWidgetInfo = AppWidgetManagerCompat
.getInstance(launcher).findProvider(info.providerName, info.user);
if (appWidgetInfo == null) {
return;
}
WidgetAddFlowHandler addFlowHandler = new WidgetAddFlowHandler(appWidgetInfo);
if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
// This should not happen, as we make sure that an Id is allocated during bind.
return;
}
addFlowHandler.startBindFlow(launcher, info.appWidgetId, info,
Launcher.REQUEST_BIND_PENDING_APPWIDGET);
} else {
addFlowHandler.startConfigActivity(launcher, info, Launcher.REQUEST_RECONFIGURE_APPWIDGET);
}
} else {
final String packageName = info.providerName.getPackageName();
onClickPendingAppItem(v, launcher, packageName, info.installProgress >= 0);
}
}
private static void onClickPendingAppItem(View v, Launcher launcher, String packageName,
boolean downloadStarted) {
if (downloadStarted) {
// If the download has started, simply direct to the market app.
startMarketIntentForPackage(v, launcher, packageName);
return;
}
new AlertDialog.Builder(launcher)
.setTitle(R.string.abandoned_promises_title)
.setMessage(R.string.abandoned_promise_explanation)
.setPositiveButton(R.string.abandoned_search,
(d, i) -> startMarketIntentForPackage(v, launcher, packageName))
.setNeutralButton(R.string.abandoned_clean_this,
(d, i) -> launcher.getWorkspace()
.removeAbandonedPromise(packageName, Process.myUserHandle()))
.create().show();
}
private static void startMarketIntentForPackage(View v, Launcher launcher, String packageName) {
ItemInfo item = (ItemInfo) v.getTag();
Intent intent = new PackageManagerHelper(launcher).getMarketIntent(packageName);
launcher.startActivitySafely(v, intent, item, null);
}
/**
* Event handler for an app shortcut click.
*
* @param v The view that was clicked. Must be a tagged with a {@link WorkspaceItemInfo}.
*/
public static void onClickAppShortcut(View v, WorkspaceItemInfo shortcut, Launcher launcher,
@Nullable String sourceContainer) {
if (shortcut.isDisabled()) {
final int disabledFlags = shortcut.runtimeStatusFlags
& WorkspaceItemInfo.FLAG_DISABLED_MASK;
if ((disabledFlags &
~FLAG_DISABLED_SUSPENDED &
~FLAG_DISABLED_QUIET_USER) == 0) {
// If the app is only disabled because of the above flags, launch activity anyway.
// Framework will tell the user why the app is suspended.
} else {
if (!TextUtils.isEmpty(shortcut.disabledMessage)) {
// Use a message specific to this shortcut, if it has one.
Toast.makeText(launcher, shortcut.disabledMessage, Toast.LENGTH_SHORT).show();
return;
}
// Otherwise just use a generic error message.
int error = R.string.activity_not_available;
if ((shortcut.runtimeStatusFlags & FLAG_DISABLED_SAFEMODE) != 0) {
error = R.string.safemode_shortcut_error;
} else if ((shortcut.runtimeStatusFlags & FLAG_DISABLED_BY_PUBLISHER) != 0 ||
(shortcut.runtimeStatusFlags & FLAG_DISABLED_LOCKED_USER) != 0) {
error = R.string.shortcut_not_available;
}
Toast.makeText(launcher, error, Toast.LENGTH_SHORT).show();
return;
}
}
// Check for abandoned promise
if ((v instanceof BubbleTextView) && shortcut.hasPromiseIconUi()) {
String packageName = shortcut.intent.getComponent() != null ?
shortcut.intent.getComponent().getPackageName() : shortcut.intent.getPackage();
if (!TextUtils.isEmpty(packageName)) {
onClickPendingAppItem(v, launcher, packageName,
shortcut.hasStatusFlag(WorkspaceItemInfo.FLAG_INSTALL_SESSION_ACTIVE));
return;
}
}
// Start activities
startAppShortcutOrInfoActivity(v, shortcut, launcher, sourceContainer);
}
private static void startAppShortcutOrInfoActivity(View v, ItemInfo item, Launcher launcher,
@Nullable String sourceContainer) {
if (TestProtocol.sDebugTracing) {
android.util.Log.d(TestProtocol.NO_START_TAG,
"startAppShortcutOrInfoActivity");
}
Intent intent;
if (item instanceof PromiseAppInfo) {
PromiseAppInfo promiseAppInfo = (PromiseAppInfo) item;
intent = promiseAppInfo.getMarketIntent(launcher);
} else {
intent = item.getIntent();
}
if (intent == null) {
throw new IllegalArgumentException("Input must have a valid intent");
}
if (item instanceof WorkspaceItemInfo) {
WorkspaceItemInfo si = (WorkspaceItemInfo) item;
if (si.hasStatusFlag(WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI)
&& Intent.ACTION_VIEW.equals(intent.getAction())) {
// make a copy of the intent that has the package set to null
// we do this because the platform sometimes disables instant
// apps temporarily (triggered by the user) and fallbacks to the
// web ui. This only works though if the package isn't set
intent = new Intent(intent);
intent.setPackage(null);
}
}
if (v != null && launcher.getAppTransitionManager().supportsAdaptiveIconAnimation()) {
// Preload the icon to reduce latency b/w swapping the floating view with the original.
FloatingIconView.fetchIcon(launcher, v, item, true /* isOpening */);
}
launcher.startActivitySafely(v, intent, item, sourceContainer);
}
}