diff options
| -rw-r--r-- | core/java/android/os/SELinux.java | 71 | ||||
| -rw-r--r-- | core/java/android/os/StatFs.java | 86 | ||||
| -rw-r--r-- | core/jni/Android.mk | 1 | ||||
| -rw-r--r-- | core/jni/AndroidRuntime.cpp | 2 | ||||
| -rw-r--r-- | core/jni/android_os_SELinux.cpp | 39 | ||||
| -rw-r--r-- | core/jni/android_os_StatFs.cpp | 163 | ||||
| -rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java | 4 | ||||
| -rw-r--r-- | services/java/com/android/server/WallpaperManagerService.java | 7 | ||||
| -rw-r--r-- | services/java/com/android/server/pm/PackageManagerService.java | 8 | ||||
| -rw-r--r-- | services/java/com/android/server/usb/UsbSettingsManager.java | 4 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 6 |
11 files changed, 186 insertions, 205 deletions
diff --git a/core/java/android/os/SELinux.java b/core/java/android/os/SELinux.java index 90cfa37..c05a974 100644 --- a/core/java/android/os/SELinux.java +++ b/core/java/android/os/SELinux.java @@ -1,5 +1,25 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package android.os; +import android.util.Slog; + +import java.io.IOException; +import java.io.File; import java.io.FileDescriptor; /** @@ -9,6 +29,8 @@ import java.io.FileDescriptor; */ public class SELinux { + private static final String TAG = "SELinux"; + /** * Determine whether SELinux is disabled or enabled. * @return a boolean indicating whether SELinux is enabled. @@ -102,4 +124,53 @@ public class SELinux { * @return a boolean indicating whether permission was granted. */ public static final native boolean checkSELinuxAccess(String scon, String tcon, String tclass, String perm); + + /** + * Restores a file to its default SELinux security context. + * If the system is not compiled with SELinux, then {@code true} + * is automatically returned. + * If SELinux is compiled in, but disabled, then {@code true} is + * returned. + * + * @param pathname The pathname of the file to be relabeled. + * @return a boolean indicating whether the relabeling succeeded. + * @exception NullPointerException if the pathname is a null object. + */ + public static boolean restorecon(String pathname) throws NullPointerException { + if (pathname == null) { throw new NullPointerException(); } + return native_restorecon(pathname); + } + + /** + * Restores a file to its default SELinux security context. + * If the system is not compiled with SELinux, then {@code true} + * is automatically returned. + * If SELinux is compiled in, but disabled, then {@code true} is + * returned. + * + * @param pathname The pathname of the file to be relabeled. + * @return a boolean indicating whether the relabeling succeeded. + */ + private static native boolean native_restorecon(String pathname); + + /** + * Restores a file to its default SELinux security context. + * If the system is not compiled with SELinux, then {@code true} + * is automatically returned. + * If SELinux is compiled in, but disabled, then {@code true} is + * returned. + * + * @param file The File object representing the path to be relabeled. + * @return a boolean indicating whether the relabeling succeeded. + * @exception NullPointerException if the file is a null object. + */ + public static boolean restorecon(File file) throws NullPointerException { + try { + return native_restorecon(file.getCanonicalPath()); + } catch (IOException e) { + Slog.e(TAG, "Error getting canonical path. Restorecon failed for " + + file.getPath(), e); + return false; + } + } } diff --git a/core/java/android/os/StatFs.java b/core/java/android/os/StatFs.java index 912bfdf..ca7fdba 100644 --- a/core/java/android/os/StatFs.java +++ b/core/java/android/os/StatFs.java @@ -16,59 +16,77 @@ package android.os; +import libcore.io.ErrnoException; +import libcore.io.Libcore; +import libcore.io.StructStatFs; + /** - * Retrieve overall information about the space on a filesystem. This is a - * Wrapper for Unix statfs(). + * Retrieve overall information about the space on a filesystem. This is a + * wrapper for Unix statfs(). */ public class StatFs { + private StructStatFs mStat; + /** - * Construct a new StatFs for looking at the stats of the - * filesystem at <var>path</var>. Upon construction, the stat of - * the file system will be performed, and the values retrieved available - * from the methods on this class. - * - * @param path A path in the desired file system to state. + * Construct a new StatFs for looking at the stats of the filesystem at + * {@code path}. Upon construction, the stat of the file system will be + * performed, and the values retrieved available from the methods on this + * class. + * + * @param path path in the desired file system to stat. */ - public StatFs(String path) { native_setup(path); } - + public StatFs(String path) { + mStat = doStat(path); + } + + private static StructStatFs doStat(String path) { + try { + return Libcore.os.statfs(path); + } catch (ErrnoException e) { + throw new IllegalArgumentException("Invalid path: " + path, e); + } + } + /** - * Perform a restat of the file system referenced by this object. This - * is the same as re-constructing the object with the same file system - * path, and the new stat values are available upon return. + * Perform a restat of the file system referenced by this object. This is + * the same as re-constructing the object with the same file system path, + * and the new stat values are available upon return. */ - public void restat(String path) { native_restat(path); } - - @Override - protected void finalize() { native_finalize(); } + public void restat(String path) { + mStat = doStat(path); + } /** - * The size, in bytes, of a block on the file system. This corresponds - * to the Unix statfs.f_bsize field. + * The size, in bytes, of a block on the file system. This corresponds to + * the Unix {@code statfs.f_bsize} field. */ - public native int getBlockSize(); + public int getBlockSize() { + return (int) mStat.f_bsize; + } /** - * The total number of blocks on the file system. This corresponds - * to the Unix statfs.f_blocks field. + * The total number of blocks on the file system. This corresponds to the + * Unix {@code statfs.f_blocks} field. */ - public native int getBlockCount(); + public int getBlockCount() { + return (int) mStat.f_blocks; + } /** * The total number of blocks that are free on the file system, including - * reserved blocks (that are not available to normal applications). This - * corresponds to the Unix statfs.f_bfree field. Most applications will - * want to use {@link #getAvailableBlocks()} instead. + * reserved blocks (that are not available to normal applications). This + * corresponds to the Unix {@code statfs.f_bfree} field. Most applications + * will want to use {@link #getAvailableBlocks()} instead. */ - public native int getFreeBlocks(); + public int getFreeBlocks() { + return (int) mStat.f_bfree; + } /** * The number of blocks that are free on the file system and available to - * applications. This corresponds to the Unix statfs.f_bavail field. + * applications. This corresponds to the Unix {@code statfs.f_bavail} field. */ - public native int getAvailableBlocks(); - - private int mNativeContext; - private native void native_restat(String path); - private native void native_setup(String path); - private native void native_finalize(); + public int getAvailableBlocks() { + return (int) mStat.f_bavail; + } } diff --git a/core/jni/Android.mk b/core/jni/Android.mk index b5a2f98..6f3653d 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -67,7 +67,6 @@ LOCAL_SRC_FILES:= \ android_os_ParcelFileDescriptor.cpp \ android_os_Parcel.cpp \ android_os_SELinux.cpp \ - android_os_StatFs.cpp \ android_os_SystemClock.cpp \ android_os_SystemProperties.cpp \ android_os_Trace.cpp \ diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 7a23747..d08e651 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -134,7 +134,6 @@ extern int register_android_os_MessageQueue(JNIEnv* env); extern int register_android_os_Parcel(JNIEnv* env); extern int register_android_os_ParcelFileDescriptor(JNIEnv *env); extern int register_android_os_SELinux(JNIEnv* env); -extern int register_android_os_StatFs(JNIEnv *env); extern int register_android_os_SystemProperties(JNIEnv *env); extern int register_android_os_SystemClock(JNIEnv* env); extern int register_android_os_Trace(JNIEnv* env); @@ -1148,7 +1147,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_os_MessageQueue), REG_JNI(register_android_os_ParcelFileDescriptor), REG_JNI(register_android_os_SELinux), - REG_JNI(register_android_os_StatFs), REG_JNI(register_android_os_Trace), REG_JNI(register_android_os_UEventObserver), REG_JNI(register_android_net_LocalSocketImpl), diff --git a/core/jni/android_os_SELinux.cpp b/core/jni/android_os_SELinux.cpp index 40443ff..e813c38 100644 --- a/core/jni/android_os_SELinux.cpp +++ b/core/jni/android_os_SELinux.cpp @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #define LOG_TAG "SELinuxJNI" #include <utils/Log.h> @@ -6,6 +22,7 @@ #include "android_runtime/AndroidRuntime.h" #ifdef HAVE_SELINUX #include "selinux/selinux.h" +#include "selinux/android.h" #endif #include <errno.h> @@ -458,6 +475,27 @@ namespace android { } /* + * Function: native_restorecon + * Purpose: restore default SELinux security context + * Parameters: pathname: the pathname for the file to be relabeled + * Returns: boolean: (true) file label successfully restored, (false) otherwise + * Exceptions: none + */ + static jboolean native_restorecon(JNIEnv *env, jobject clazz, jstring pathname) { +#ifdef HAVE_SELINUX + if (isSELinuxDisabled) + return true; + + const char *file = const_cast<char *>(env->GetStringUTFChars(pathname, NULL)); + int ret = selinux_android_restorecon(file); + env->ReleaseStringUTFChars(pathname, file); + return (ret == 0); +#else + return true; +#endif + } + + /* * JNI registration. */ static JNINativeMethod method_table[] = { @@ -472,6 +510,7 @@ namespace android { { "getPidContext" , "(I)Ljava/lang/String;" , (void*)getPidCon }, { "isSELinuxEnforced" , "()Z" , (void*)isSELinuxEnforced}, { "isSELinuxEnabled" , "()Z" , (void*)isSELinuxEnabled }, + { "native_restorecon" , "(Ljava/lang/String;)Z" , (void*)native_restorecon}, { "setBooleanValue" , "(Ljava/lang/String;Z)Z" , (void*)setBooleanValue }, { "setFileContext" , "(Ljava/lang/String;Ljava/lang/String;)Z" , (void*)setFileCon }, { "setFSCreateContext" , "(Ljava/lang/String;)Z" , (void*)setFSCreateCon }, diff --git a/core/jni/android_os_StatFs.cpp b/core/jni/android_os_StatFs.cpp deleted file mode 100644 index 79d8fef..0000000 --- a/core/jni/android_os_StatFs.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2007, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if INCLUDE_SYS_MOUNT_FOR_STATFS -#include <sys/mount.h> -#else -#include <sys/statfs.h> -#endif - -#include <errno.h> - -#include "jni.h" -#include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" - - -namespace android -{ - -// ---------------------------------------------------------------------------- - -struct fields_t { - jfieldID context; -}; -static fields_t fields; - -// ---------------------------------------------------------------------------- - -static jint -android_os_StatFs_getBlockSize(JNIEnv *env, jobject thiz) -{ - struct statfs *stat = (struct statfs *)env->GetIntField(thiz, fields.context); - return stat->f_bsize; -} - -static jint -android_os_StatFs_getBlockCount(JNIEnv *env, jobject thiz) -{ - struct statfs *stat = (struct statfs *)env->GetIntField(thiz, fields.context); - return stat->f_blocks; -} - -static jint -android_os_StatFs_getFreeBlocks(JNIEnv *env, jobject thiz) -{ - struct statfs *stat = (struct statfs *)env->GetIntField(thiz, fields.context); - return stat->f_bfree; -} - -static jint -android_os_StatFs_getAvailableBlocks(JNIEnv *env, jobject thiz) -{ - struct statfs *stat = (struct statfs *)env->GetIntField(thiz, fields.context); - return stat->f_bavail; -} - -static void -android_os_StatFs_native_restat(JNIEnv *env, jobject thiz, jstring path) -{ - if (path == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); - return; - } - - // get the object handle - struct statfs *stat = (struct statfs *)env->GetIntField(thiz, fields.context); - if (stat == NULL) { - jniThrowException(env, "java/lang/NoSuchFieldException", NULL); - return; - } - - const char* pathstr = env->GetStringUTFChars(path, NULL); - if (pathstr == NULL) { - jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); - return; - } - - // note that stat will contain the new file data corresponding to - // pathstr - if (statfs(pathstr, stat) != 0) { - ALOGE("statfs %s failed, errno: %d", pathstr, errno); - delete stat; - env->SetIntField(thiz, fields.context, 0); - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); - } - // Release pathstr - env->ReleaseStringUTFChars(path, pathstr); -} - -static void -android_os_StatFs_native_setup(JNIEnv *env, jobject thiz, jstring path) -{ - if (path == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); - return; - } - - struct statfs* stat = new struct statfs; - if (stat == NULL) { - jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); - return; - } - env->SetIntField(thiz, fields.context, (int)stat); - android_os_StatFs_native_restat(env, thiz, path); -} - -static void -android_os_StatFs_native_finalize(JNIEnv *env, jobject thiz) -{ - struct statfs *stat = (struct statfs *)env->GetIntField(thiz, fields.context); - if (stat != NULL) { - delete stat; - env->SetIntField(thiz, fields.context, 0); - } -} - -// ---------------------------------------------------------------------------- - -static JNINativeMethod gMethods[] = { - {"getBlockSize", "()I", (void *)android_os_StatFs_getBlockSize}, - {"getBlockCount", "()I", (void *)android_os_StatFs_getBlockCount}, - {"getFreeBlocks", "()I", (void *)android_os_StatFs_getFreeBlocks}, - {"getAvailableBlocks", "()I", (void *)android_os_StatFs_getAvailableBlocks}, - {"native_setup", "(Ljava/lang/String;)V", (void *)android_os_StatFs_native_setup}, - {"native_finalize", "()V", (void *)android_os_StatFs_native_finalize}, - {"native_restat", "(Ljava/lang/String;)V", (void *)android_os_StatFs_native_restat}, -}; - - -int register_android_os_StatFs(JNIEnv *env) -{ - jclass clazz; - - clazz = env->FindClass("android/os/StatFs"); - if (clazz == NULL) { - ALOGE("Can't find android/os/StatFs"); - return -1; - } - - fields.context = env->GetFieldID(clazz, "mNativeContext", "I"); - if (fields.context == NULL) { - ALOGE("Can't find StatFs.mNativeContext"); - return -1; - } - - return AndroidRuntime::registerNativeMethods(env, - "android/os/StatFs", gMethods, NELEM(gMethods)); -} - -} // namespace android diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java index 02eeedf..5fa6dbf 100644 --- a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java @@ -230,7 +230,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback, private KeyguardUpdateMonitor mUpdateMonitor; - private boolean mScreenOn = false; + private boolean mScreenOn; // last known state of the cellular connection private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE; @@ -318,6 +318,8 @@ public class KeyguardViewMediator implements KeyguardViewCallback, final ContentResolver cr = mContext.getContentResolver(); mShowLockIcon = (Settings.System.getInt(cr, "show_status_bar_lock", 0) == 1); + mScreenOn = mPM.isScreenOn(); + mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0); String soundPath = Settings.System.getString(cr, Settings.System.LOCK_SOUND); if (soundPath != null) { diff --git a/services/java/com/android/server/WallpaperManagerService.java b/services/java/com/android/server/WallpaperManagerService.java index d97d335..8a08277 100644 --- a/services/java/com/android/server/WallpaperManagerService.java +++ b/services/java/com/android/server/WallpaperManagerService.java @@ -45,6 +45,7 @@ import android.os.RemoteException; import android.os.FileObserver; import android.os.ParcelFileDescriptor; import android.os.RemoteCallbackList; +import android.os.SELinux; import android.os.ServiceManager; import android.os.SystemClock; import android.os.UserId; @@ -639,8 +640,12 @@ class WallpaperManagerService extends IWallpaperManager.Stub { FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, -1, -1); } - ParcelFileDescriptor fd = ParcelFileDescriptor.open(new File(dir, WALLPAPER), + File file = new File(dir, WALLPAPER); + ParcelFileDescriptor fd = ParcelFileDescriptor.open(file, MODE_CREATE|MODE_READ_WRITE); + if (!SELinux.restorecon(file)) { + return null; + } wallpaper.name = name; return fd; } catch (FileNotFoundException e) { diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java index 3501e47..8c5a090 100644 --- a/services/java/com/android/server/pm/PackageManagerService.java +++ b/services/java/com/android/server/pm/PackageManagerService.java @@ -96,6 +96,7 @@ import android.os.Parcel; import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; +import android.os.SELinux; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; @@ -6418,6 +6419,10 @@ public class PackageManagerService extends IPackageManager.Stub { return false; } + if (!SELinux.restorecon(newCodeFile)) { + return false; + } + return true; } } @@ -7399,6 +7404,9 @@ public class PackageManagerService extends IPackageManager.Stub { FileUtils.setPermissions( tmpPackageFile.getCanonicalPath(), FileUtils.S_IRUSR|FileUtils.S_IWUSR, -1, -1); + if (!SELinux.restorecon(tmpPackageFile)) { + return null; + } } catch (IOException e) { Slog.e(TAG, "Trouble getting the canoncical path for a temp file."); return null; diff --git a/services/java/com/android/server/usb/UsbSettingsManager.java b/services/java/com/android/server/usb/UsbSettingsManager.java index 7dde340..9b3459b 100644 --- a/services/java/com/android/server/usb/UsbSettingsManager.java +++ b/services/java/com/android/server/usb/UsbSettingsManager.java @@ -545,6 +545,10 @@ class UsbSettingsManager { defaultPackage = mDevicePreferenceMap.get(new DeviceFilter(device)); } + // Send broadcast to running activity with registered intent + mContext.sendBroadcast(intent); + + // Start activity with registered intent resolveActivity(intent, matches, defaultPackage, device, null); } diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 23b1b44..bb09704 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -1240,14 +1240,14 @@ public class WifiStateMachine extends StateMachine { ip settings */ InterfaceConfiguration ifcg = null; try { - ifcg = mNwService.getInterfaceConfig(mInterfaceName); + ifcg = mNwService.getInterfaceConfig(mTetherInterfaceName); if (ifcg != null) { ifcg.setLinkAddress( new LinkAddress(NetworkUtils.numericToInetAddress("0.0.0.0"), 0)); - mNwService.setInterfaceConfig(mInterfaceName, ifcg); + mNwService.setInterfaceConfig(mTetherInterfaceName, ifcg); } } catch (Exception e) { - loge("Error resetting interface " + mInterfaceName + ", :" + e); + loge("Error resetting interface " + mTetherInterfaceName + ", :" + e); } if (mCm.untether(mTetherInterfaceName) != ConnectivityManager.TETHER_ERROR_NO_ERROR) { |
