Rk3399客户 adb 和apk限制安装需求

这篇博客介绍了如何修改Android设备的源代码以实现adb调试的默认关闭,以及在U盘插入特定文件adb.txt时自动开启adb调试。同时,文章还展示了如何限制U盘和SD卡上的APK安装,并禁用蓝牙功能。通过这些修改,设备的安全性和管理性得到了提升。
摘要由CSDN通过智能技术生成


1.开机默认关闭adb调试

frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
                 com.android.internal.R.bool.config_usbChargingMessage);
 
         // make sure the ADB_ENABLED setting value matches the current state
+               // modify by luoyalong 20210622 for  adb default close begin
         try {
             Settings.Global.putInt(mContentResolver,
-                    Settings.Global.ADB_ENABLED, mAdbEnabled ? 1 : 0);
+                    Settings.Global.ADB_ENABLED, 0);

2.当插入的U盘有adb.txt 文件时,打开adb调试

+++ b/packages/apps/Settings/AndroidManifest.xml
@@ -86,7 +86,6 @@
     <uses-permission android:name="android.permission.PEERS_MAC_ADDRESS"/>
     <uses-permission android:name="android.permission.MANAGE_NOTIFICATIONS"/>
     <uses-permission android:name="android.permission.DELETE_PACKAGES"/>
-
     <application android:label="@string/settings_label"
             android:icon="@mipmap/ic_launcher_settings"
             android:taskAffinity=""
@@ -3028,13 +3027,22 @@
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                 android:value="true" />
         </activity>
-        
+        <!--//modify by luoyalong 20210622 for open adb when U has adb.txt begin-->
         <receiver android:name="HdmiReceiver">
             <intent-filter android:priority="1000">
                 <action android:name="android.intent.action.HDMI_PLUG"/>
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
+                <action android:name="android.intent.action.ACTION_SHUTDOWN" />
             </intent-filter>
        </receiver>
+        <receiver android:name="MediaMountReceiver">
+            <intent-filter android:priority="1000">
+                <action android:name="android.intent.action.MEDIA_MOUNTED" />
+                <action android:name="android.intent.action.MEDIA_REMOVED" />
+                               <data android:scheme="file"/>
+            </intent-filter>
+       </receiver>        
+          <!--//modify by luoyalong 20210622 for open adb when U has adb.txt end-->
         <!-- activity for gesture settings -->
         <activity android:name="Settings$GestureSettingsActivity"
                   android:label="@string/gesture_preference_title"
diff --git a/packages/apps/Settings/src/com/android/settings/HdmiReceiver.java b/packages/apps/Settings/src/com/android/settings/HdmiReceiver.java
old mode 100644
new mode 100755
index 6129f78..436d302
--- a/packages/apps/Settings/src/com/android/settings/HdmiReceiver.java
+++ b/packages/apps/Settings/src/com/android/settings/HdmiReceiver.java
@@ -58,7 +58,11 @@ public class HdmiReceiver extends BroadcastReceiver {
                    }catch (RemoteException doe) {
                        mDisplayManagement = null;        
                    }
-       Log.d(TAG,"hdmi receiver action="+action);
+       //modify by luoyalong 20210622 for open adb when U has adb.txt begin
+          if("android.intent.action.ACTION_SHUTDOWN".equals(action)){
+                  SystemProperties.set("persist.sys.sdandu",""); 
+          }
+          //modify by luoyalong 20210622 for open adb when U has adb.txt end
        if (action.equals(HDMI_ACTION)) {
            String enable = null;
            String scale = null;
diff --git a/packages/apps/Settings/src/com/android/settings/MediaMountReceiver.java b/packages/apps/Settings/src/com/android/settings/MediaMountReceiver.java
new file mode 100755
index 0000000..3bd7ff8
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/MediaMountReceiver.java
@@ -0,0 +1,105 @@
+
+
+package com.android.settings;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.BroadcastReceiver;
+import android.os.AsyncTask;
+import android.os.RemoteException;
+import android.os.IPowerManager;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.preference.SeekBarPreference;
+import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
+import android.util.AttributeSet;
+import android.util.Log;
+
+import java.util.Map;
+import java.io.*;
+
+import android.os.SystemProperties;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.os.SystemProperties;
+import android.content.ContentResolver;
+
+import java.io.RandomAccessFile;
+
+import static android.provider.Settings.System.HDMI_LCD_TIMEOUT;
+import android.widget.Toast;
+
+import android.os.DisplayOutputManager;
+import com.android.settings.R;
+import java.io.File;
+//modify by luoyalong 20210622 for open adb when U has adb.txt begin
+public class MediaMountReceiver extends BroadcastReceiver {
+   private Context mcontext;
+   public String sM=",";
+   @Override
+   public void onReceive(Context context, Intent intent) {
+       mcontext = context;
+       String action=intent.getAction();
+       Log.e("lyl","hdmi receiver action="+action);
+       Log.e("lyl","hdm22222="+intent.getData().getPath());//storage/7C5B-BE35
+          boolean sCount=true;
+               String str = intent.getData().getPath();
+               String[] strs=str.split("/");
+          if("android.intent.action.MEDIA_MOUNTED".equals(action)){
+                  if(!str.contains("/storage/emulated/")){
+                       sM=strs[2]+","+SystemProperties.get("persist.sys.sdandu");
+                       Log.e("lyl","sM="+sM);
+                       Log.e("lyl","strs[2]="+strs[2]);
+                  }
+            File path = new File(intent.getData().getPath());
+            File[] files = path.listFiles();// 读取
+            getFileName(files); 
+          }
+          String sm2=SystemProperties.get("persist.sys.sdandu");
+          if(sm2 != null){
+               String[] strarray=sm2.split(",");
+               for (int i = 0; i < strarray.length; i++){
+                       if(strarray[i] != null){
+                       if(strs[2].equals(strarray[i])){
+                               sCount=false;
+                       }
+                       }
+               }        
+          }            
+          
+          if(sm2 == null){
+                       SystemProperties.set("persist.sys.sdandu",sM); 
+          }else{
+                       if(sCount){
+                               SystemProperties.set("persist.sys.sdandu",sM);
+                       }
+          }
+   }
+       public void getFileName(File[] files) {
+               try{
+        if (files != null) {// 先判断目录是否为空,否则会报空指针
+            String fileName = null;
+            for (File file : files) {
+                if (file.isDirectory()) {
+                   // Log.e("lyl", "若是文件目录。继续读1" + file.getName().toString() + file.getPath().toString());
+                    getFileName(file.listFiles());
+                    //Log.e("lyl", "若是文件目录。继续读2" + file.getName().toString() + file.getPath().toString());
+                } else {
+                    fileName = file.getName();
+                    if (fileName.equals("adb.txt")) {
+                        //HashMap map = new HashMap();
+                        String s = fileName.substring(0, fileName.lastIndexOf(".")).toString();
+                        Log.e("lyl", "文件名txt::  " + s);
+                                               Settings.Global.putInt(mcontext.getContentResolver(),
+                                               Settings.Global.ADB_ENABLED, 1);
+
+                    }
+                }
+            }
+        }
+               }catch(Exception e){}
+       }
+   
+}
+//modify by luoyalong 20210622 for open adb when U has adb.txt end
\ No newline at end of file

3.限制U盘和SD卡中的apk安装

--- a/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java
+++ b/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java
@@ -454,14 +454,25 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
             finish();
             return;
         }
-               String sU=packageUri+",";
-               // modify by luoyalong 20210619 for apk install imit begin
-               Log.e("lyl","packageUri  "+packageUri);
-               if(sU.contains("file:///storage/emulated/")){
+               // modify by luoyalong 20210622 for apk install imit begin
+               String sU=packageUri+"";
+               String sM=SystemProperties.get("persist.sys.sdandu");
+               String[] strarray=sM.split(",");
+               for (int i = 0; i < strarray.length; i++){
+                       Log.e("lyl","strarray[i] "+strarray[i]);
+                       if(strarray[i] != null){
+                       if(sU.contains(strarray[i])){
+                               Toast.makeText(getApplicationContext(), "无法安装apk...",Toast.LENGTH_SHORT).show();
+                               finish();
+                               return;                                 
+                       }
+                       }
+               }

4.去掉蓝牙功能

+++ b/device/rockchip/common/BoardConfig.mk
@@ -225,7 +225,9 @@ BUILD_WITH_CRYPTO := false
 BOARD_USES_GENERIC_AUDIO ?= true
 
 # Wifi&Bluetooth
-BOARD_HAVE_BLUETOOTH ?= true
+#modify by luoyalong 20210624 begin
+BOARD_HAVE_BLUETOOTH ?= false
+#modify by luoyalong 20210624 end
 BLUETOOTH_USE_BPLUS ?= false
 BOARD_HAVE_BLUETOOTH_BCM ?= false
 BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR ?= device/rockchip/$(TARGET_BOARD_PLATFORM)/bluetooth
diff --git a/device/rockchip/common/wifi_bt_common.mk b/device/rockchip/common/wifi_bt_common.mk
old mode 100644
new mode 100755
index e5fbda3..f6d19d6
--- a/device/rockchip/common/wifi_bt_common.mk
+++ b/device/rockchip/common/wifi_bt_common.mk
@@ -19,7 +19,9 @@ endif
 
 # bluetooth support
 ifeq ($(strip $(BOARD_CONNECTIVITY_VENDOR)), Broadcom)
-BOARD_HAVE_BLUETOOTH := true
+#modify by luoyalong 20210624 begin
+BOARD_HAVE_BLUETOOTH := false 
+#modify by luoyalong 20210624 end
 BOARD_HAVE_BLUETOOTH_BCM := true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心有纤纤结

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值