-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
2,811 additions
and
2,722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package com.bintianqi.owndroid; | ||
|
||
interface IUserService { | ||
void destroy() = 16777114; | ||
String execute(String command) = 1; | ||
int getUid() = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.bintianqi.owndroid | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.util.Log | ||
import com.bintianqi.owndroid.dpm.getDPM | ||
import com.bintianqi.owndroid.dpm.getReceiver | ||
|
||
class ApiReceiver: BroadcastReceiver() { | ||
@SuppressLint("NewApi") | ||
override fun onReceive(context: Context, intent: Intent) { | ||
val sharedPrefs = context.getSharedPreferences("data", Context.MODE_PRIVATE) | ||
if(sharedPrefs.getBoolean("enable_api", false)) return | ||
val key = sharedPrefs.getString("api_key", null) | ||
if(key != null && key == intent.getStringExtra("key")) { | ||
val dpm = context.getDPM() | ||
val receiver = context.getReceiver() | ||
val app = intent.getStringExtra("package") ?: "" | ||
try { | ||
val ok = when(intent.action) { | ||
"com.bintianqi.owndroid.action.HIDE" -> dpm.setApplicationHidden(receiver, app, true) | ||
"com.bintianqi.owndroid.action.UNHIDE" -> dpm.setApplicationHidden(receiver, app, false) | ||
"com.bintianqi.owndroid.action.SUSPEND" -> dpm.setPackagesSuspended(receiver, arrayOf(app), true).isEmpty() | ||
"com.bintianqi.owndroid.action.UNSUSPEND" -> dpm.setPackagesSuspended(receiver, arrayOf(app), false).isEmpty() | ||
"com.bintianqi.owndroid.action.LOCK" -> { dpm.lockNow(); true } | ||
else -> { | ||
Log.w(TAG, "Invalid action") | ||
resultData = "Invalid action" | ||
false | ||
} | ||
} | ||
if(!ok) resultCode = 1 | ||
} catch(e: Exception) { | ||
e.printStackTrace() | ||
val message = (e::class.qualifiedName ?: "Exception") + ": " + (e.message ?: "") | ||
Log.w(TAG, message) | ||
resultCode = 1 | ||
resultData = message | ||
} | ||
} else { | ||
Log.w(TAG, "Unauthorized") | ||
resultCode = 1 | ||
resultData = "Unauthorized" | ||
} | ||
} | ||
companion object { | ||
private const val TAG = "API" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.