2

I have installed application as a user mode and not rooted. Hence some of the android.permissions like write permission are ignored and not set. was able to identify from packages.xml and also from the command "adb shell dumpsys package "

I want to set write permission to the application that I installed to the device. I have access to android OS code, Is there a way to grant the permission? either by sepolicy change??

Note : device is not UI(user interface)

Please help!!

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package=<package-name>
      xmlns:tools="http://schemas.android.com/tools"
      android:versionCode="1"
      android:versionName="1.0">

    <uses-permission android:name="android.permission.WRITE_SETTINGS"  tools:ignore="ProtectedPermissions" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ProtectedPermissions" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application android:label="@string/app_name" >
        <service android:name=<service-name>
            <intent-filter >
              ---
            </intent-filter>
        </service>
    </application>
</manifest> 
Knight
  • 21
  • 1
  • 4

2 Answers2

5

On a rooted device you can use the following command:

adb shell appops set foo.bar.package WRITE_SETTINGS allow
Dobrin Tinchev
  • 383
  • 3
  • 10
1

use this command adb shell pm grant you package android.permission.WRITE_SECURE_SETTINGS and only system app and rooted app can write the setting but this command help you to write setting.

   public void setSettingsAutomaticDateTimeIfNeeded() {
    String timeZoneSettings = android.provider.Settings.Global.getString(
            this.getContentResolver(),
            android.provider.Settings.Global.AUTO_TIME_ZONE);
    Log.e(TAG, "auot update check true");
    if (timeZoneSettings.contentEquals("0")) {
        android.provider.Settings.Global.putString(
                this.getContentResolver(),
                Settings.Global.AUTO_TIME_ZONE, "1");
        Log.e(TAG, "Auto update checked make true");
    }

    String timeSettings = android.provider.Settings.Global.getString(
            this.getContentResolver(),
            android.provider.Settings.Global.AUTO_TIME);
    Log.e(TAG, "auot update check true");
    if (timeSettings.contentEquals("0")) {
        android.provider.Settings.Global.putString(
                this.getContentResolver(),
                Settings.Global.AUTO_TIME, "1");
        Log.e(TAG, "Auto update checked make true");
    }
}

and add this inot manifest

 <uses-permission
    android:name="android.permission.WRITE_SETTINGS"
    tools:ignore="ProtectedPermissions" />
<uses-permission
    android:name="android.permission.WRITE_SECURE_SETTINGS"
    tools:ignore="ProtectedPermissions" />
Amit pandey
  • 1,149
  • 1
  • 4
  • 15
  • 2
    I tried the same, as it is non rooted application I am getting following error. Operation not allowed: java.lang.SecurityException: Permission android.permission.WRITE_SETTINGS is not a changeable permission type. and yes,I am looking for WRITE_SETTINGS. – Knight Feb 06 '20 at 12:08
  • Edited my description and added manifest file. I am trying to set wifi ssid data via application, which is not allowing me to write those setting into it, as my is a user application. which stored in /data/app. – Knight Feb 06 '20 at 12:43
  • As android document these are only worked in rooted device and system app.. – Amit pandey Feb 06 '20 at 15:29
  • This actually works, but you need to disable permission checks in developer options, as described in the answers here: https://stackoverflow.com/questions/52079343/how-can-i-use-adb-to-grant-permission-without-root – NoHarmDan Apr 08 '22 at 14:31