android secure flag

This commit is contained in:
niuhuan 2021-10-29 11:38:36 +08:00
parent 7cebc1d90c
commit 6bf01d7a7b
6 changed files with 80 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import android.provider.MediaStore
import android.util.Log import android.util.Log
import android.view.Display import android.view.Display
import android.view.KeyEvent import android.view.KeyEvent
import android.view.WindowManager
import androidx.annotation.NonNull import androidx.annotation.NonNull
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterActivity
@ -98,6 +99,7 @@ class MainActivity : FlutterActivity() {
"migrate" -> androidMigrate(call.argument("path")!!) "migrate" -> androidMigrate(call.argument("path")!!)
// 获取可以迁移数据地址 // 获取可以迁移数据地址
"androidGetExtendDirs" -> androidGetExtendDirs() "androidGetExtendDirs" -> androidGetExtendDirs()
"androidSecureFlag" -> androidSecureFlag(call.argument("flag")!!)
else -> { else -> {
notImplementedToken notImplementedToken
} }
@ -338,4 +340,14 @@ class MainActivity : FlutterActivity() {
return super.onKeyDown(keyCode, event) return super.onKeyDown(keyCode, event)
} }
private fun androidSecureFlag(flag: Boolean) {
uiThreadHandler.post {
if (flag) {
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}
}
} }

View File

@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017 #Fri Oct 29 09:53:43 CST 2021
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip zipStoreBase=GRADLE_USER_HOME

View File

@ -581,4 +581,11 @@ class Method {
Future saveDownloadAndExportPath(String folder) { Future saveDownloadAndExportPath(String folder) {
return _flatInvoke("saveDownloadAndExportPath", folder); return _flatInvoke("saveDownloadAndExportPath", folder);
} }
/// (, , )
Future androidSecureFlag(bool flag) {
return _channel.invokeMethod("androidSecureFlag", {
"flag": flag,
});
}
} }

View File

@ -0,0 +1,53 @@
///
import 'dart:io';
import 'package:flutter/material.dart';
import '../Common.dart';
import '../Method.dart';
const propertyName = "androidSecureFlag";
late bool androidSecureFlag;
Future<void> initAndroidSecureFlag() async {
if (Platform.isAndroid) {
androidSecureFlag =
(await method.loadProperty(propertyName, "false")) == "true";
if (androidSecureFlag) {
await method.androidSecureFlag(true);
}
}
}
String androidSecureFlagName() {
return androidSecureFlag ? "" : "";
}
Future<void> chooseAndroidSecureFlag(BuildContext context) async {
String? result =
await chooseListDialog<String>(context, "禁止截图/禁止显示在任务视图", ["", ""]);
if (result != null) {
var target = result == "";
await method.saveProperty(propertyName, "$target");
androidSecureFlag = target;
await method.androidSecureFlag(androidSecureFlag);
}
}
Widget androidSecureFlagSetting() {
if (Platform.isAndroid) {
return StatefulBuilder(builder:
(BuildContext context, void Function(void Function()) setState) {
return ListTile(
title: Text("禁止截图/禁止显示在任务视图(仅安卓)"),
subtitle: Text(androidSecureFlagName()),
onTap: () async {
await chooseAndroidSecureFlag(context);
setState(() {});
});
});
}
return Container();
}

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pikapi/basic/config/Address.dart'; import 'package:pikapi/basic/config/Address.dart';
import 'package:pikapi/basic/config/AndroidDisplayMode.dart'; import 'package:pikapi/basic/config/AndroidDisplayMode.dart';
import 'package:pikapi/basic/config/AndroidSecureFlag.dart';
import 'package:pikapi/basic/config/AutoClean.dart'; import 'package:pikapi/basic/config/AutoClean.dart';
import 'package:pikapi/basic/config/AutoFullScreen.dart'; import 'package:pikapi/basic/config/AutoFullScreen.dart';
import 'package:pikapi/basic/config/ChooserRoot.dart'; import 'package:pikapi/basic/config/ChooserRoot.dart';
@ -63,6 +64,7 @@ class _InitScreenState extends State<InitScreen> {
await initChooserRoot(); await initChooserRoot();
await initTimeZone(); await initTimeZone();
await initDownloadAndExportPath(); await initDownloadAndExportPath();
await initAndroidSecureFlag();
// , token失效重新登录, 1 // , token失效重新登录, 1
if (await method.preLogin()) { if (await method.preLogin()) {
// token或username+password有效则直接进入登录好的界面 // token或username+password有效则直接进入登录好的界面

View File

@ -4,6 +4,7 @@ import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pikapi/basic/Common.dart'; import 'package:pikapi/basic/Common.dart';
import 'package:pikapi/basic/config/AndroidDisplayMode.dart'; import 'package:pikapi/basic/config/AndroidDisplayMode.dart';
import 'package:pikapi/basic/config/AndroidSecureFlag.dart';
import 'package:pikapi/basic/config/AutoClean.dart'; import 'package:pikapi/basic/config/AutoClean.dart';
import 'package:pikapi/basic/config/AutoFullScreen.dart'; import 'package:pikapi/basic/config/AutoFullScreen.dart';
import 'package:pikapi/basic/config/ChooserRoot.dart'; import 'package:pikapi/basic/config/ChooserRoot.dart';
@ -121,6 +122,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
), ),
Divider(), Divider(),
androidDisplayModeSetting(), androidDisplayModeSetting(),
androidSecureFlagSetting(),
Divider(), Divider(),
ListTile( ListTile(
title: Text("文件夹选择器默认路径"), title: Text("文件夹选择器默认路径"),