summaryrefslogtreecommitdiffstats
path: root/media/java/android/mtp/MtpDatabase.java
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@google.com>2014-03-07 13:29:08 -0800
committerMike Lockwood <lockwood@google.com>2014-03-12 08:46:47 -0700
commit56c85244b9be0fc6f6c2baf5f9a53f2364d5ec5e (patch)
treebb175afa849151439707cff066546fffef34d8dd /media/java/android/mtp/MtpDatabase.java
parentdaeb3936183b51db782fc433d69bb0c481e2c910 (diff)
downloadframeworks_base-56c85244b9be0fc6f6c2baf5f9a53f2364d5ec5e.zip
frameworks_base-56c85244b9be0fc6f6c2baf5f9a53f2364d5ec5e.tar.gz
frameworks_base-56c85244b9be0fc6f6c2baf5f9a53f2364d5ec5e.tar.bz2
MTP: Add support for battery level device property
Bug: 7342482 Change-Id: I810e55fe9695e2206816f57334ad14f65e9c641d
Diffstat (limited to 'media/java/android/mtp/MtpDatabase.java')
-rwxr-xr-xmedia/java/android/mtp/MtpDatabase.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index cc464db..2ddbb7d 100755
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -16,15 +16,19 @@
package android.mtp;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.ContentValues;
import android.content.IContentProvider;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.media.MediaScanner;
import android.net.Uri;
+import android.os.BatteryManager;
+import android.os.BatteryStats;
import android.os.RemoteException;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio;
@@ -113,11 +117,35 @@ public class MtpDatabase {
+ Files.FileColumns.PARENT + "=?";
private final MediaScanner mMediaScanner;
+ private MtpServer mServer;
+
+ // read from native code
+ private int mBatteryLevel;
+ private int mBatteryScale;
static {
System.loadLibrary("media_jni");
}
+ private BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
+ mBatteryScale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
+ int newLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
+ if (newLevel != mBatteryLevel) {
+ mBatteryLevel = newLevel;
+ if (mServer != null) {
+ // send device property changed event
+ mServer.sendDevicePropertyChanged(
+ MtpConstants.DEVICE_PROPERTY_BATTERY_LEVEL);
+ }
+ }
+ }
+ }
+ };
+
public MtpDatabase(Context context, String volumeName, String storagePath,
String[] subDirectories) {
native_setup();
@@ -171,6 +199,18 @@ public class MtpDatabase {
initDeviceProperties(context);
}
+ public void setServer(MtpServer server) {
+ mServer = server;
+
+ // register for battery notifications when we are connected
+ if (server != null) {
+ mContext.registerReceiver(mBatteryReceiver,
+ new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+ } else {
+ mContext.unregisterReceiver(mBatteryReceiver);
+ }
+ }
+
@Override
protected void finalize() throws Throwable {
try {
@@ -663,6 +703,7 @@ public class MtpDatabase {
MtpConstants.DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER,
MtpConstants.DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME,
MtpConstants.DEVICE_PROPERTY_IMAGE_SIZE,
+ MtpConstants.DEVICE_PROPERTY_BATTERY_LEVEL,
};
}
@@ -819,6 +860,8 @@ public class MtpDatabase {
outStringValue[imageSize.length()] = 0;
return MtpConstants.RESPONSE_OK;
+ // DEVICE_PROPERTY_BATTERY_LEVEL is implemented in the JNI code
+
default:
return MtpConstants.RESPONSE_DEVICE_PROP_NOT_SUPPORTED;
}