IMountService.java revision d967f4664f40f9a4c5262a44b19df9bbdf457d8a
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.os.storage; 18 19import android.os.Binder; 20import android.os.IBinder; 21import android.os.IInterface; 22import android.os.Parcel; 23import android.os.RemoteException; 24 25/** 26 * WARNING! Update IMountService.h and IMountService.cpp if you change this 27 * file. In particular, the ordering of the methods below must match the 28 * _TRANSACTION enum in IMountService.cpp 29 * 30 * @hide - Applications should use android.os.storage.StorageManager to access 31 * storage functions. 32 */ 33public interface IMountService extends IInterface { 34 /** Local-side IPC implementation stub class. */ 35 public static abstract class Stub extends Binder implements IMountService { 36 private static class Proxy implements IMountService { 37 private IBinder mRemote; 38 39 Proxy(IBinder remote) { 40 mRemote = remote; 41 } 42 43 public IBinder asBinder() { 44 return mRemote; 45 } 46 47 public String getInterfaceDescriptor() { 48 return DESCRIPTOR; 49 } 50 51 /** 52 * Registers an IMountServiceListener for receiving async 53 * notifications. 54 */ 55 public void registerListener(IMountServiceListener listener) throws RemoteException { 56 Parcel _data = Parcel.obtain(); 57 Parcel _reply = Parcel.obtain(); 58 try { 59 _data.writeInterfaceToken(DESCRIPTOR); 60 _data.writeStrongBinder((listener != null ? listener.asBinder() : null)); 61 mRemote.transact(Stub.TRANSACTION_registerListener, _data, _reply, 0); 62 _reply.readException(); 63 } finally { 64 _reply.recycle(); 65 _data.recycle(); 66 } 67 } 68 69 /** 70 * Unregisters an IMountServiceListener 71 */ 72 public void unregisterListener(IMountServiceListener listener) throws RemoteException { 73 Parcel _data = Parcel.obtain(); 74 Parcel _reply = Parcel.obtain(); 75 try { 76 _data.writeInterfaceToken(DESCRIPTOR); 77 _data.writeStrongBinder((listener != null ? listener.asBinder() : null)); 78 mRemote.transact(Stub.TRANSACTION_unregisterListener, _data, _reply, 0); 79 _reply.readException(); 80 } finally { 81 _reply.recycle(); 82 _data.recycle(); 83 } 84 } 85 86 /** 87 * Returns true if a USB mass storage host is connected 88 */ 89 public boolean isUsbMassStorageConnected() throws RemoteException { 90 Parcel _data = Parcel.obtain(); 91 Parcel _reply = Parcel.obtain(); 92 boolean _result; 93 try { 94 _data.writeInterfaceToken(DESCRIPTOR); 95 mRemote.transact(Stub.TRANSACTION_isUsbMassStorageConnected, _data, _reply, 0); 96 _reply.readException(); 97 _result = 0 != _reply.readInt(); 98 } finally { 99 _reply.recycle(); 100 _data.recycle(); 101 } 102 return _result; 103 } 104 105 /** 106 * Enables / disables USB mass storage. The caller should check 107 * actual status of enabling/disabling USB mass storage via 108 * StorageEventListener. 109 */ 110 public void setUsbMassStorageEnabled(boolean enable) throws RemoteException { 111 Parcel _data = Parcel.obtain(); 112 Parcel _reply = Parcel.obtain(); 113 try { 114 _data.writeInterfaceToken(DESCRIPTOR); 115 _data.writeInt((enable ? 1 : 0)); 116 mRemote.transact(Stub.TRANSACTION_setUsbMassStorageEnabled, _data, _reply, 0); 117 _reply.readException(); 118 } finally { 119 _reply.recycle(); 120 _data.recycle(); 121 } 122 } 123 124 /** 125 * Returns true if a USB mass storage host is enabled (media is 126 * shared) 127 */ 128 public boolean isUsbMassStorageEnabled() throws RemoteException { 129 Parcel _data = Parcel.obtain(); 130 Parcel _reply = Parcel.obtain(); 131 boolean _result; 132 try { 133 _data.writeInterfaceToken(DESCRIPTOR); 134 mRemote.transact(Stub.TRANSACTION_isUsbMassStorageEnabled, _data, _reply, 0); 135 _reply.readException(); 136 _result = 0 != _reply.readInt(); 137 } finally { 138 _reply.recycle(); 139 _data.recycle(); 140 } 141 return _result; 142 } 143 144 /** 145 * Mount external storage at given mount point. Returns an int 146 * consistent with MountServiceResultCode 147 */ 148 public int mountVolume(String mountPoint) throws RemoteException { 149 Parcel _data = Parcel.obtain(); 150 Parcel _reply = Parcel.obtain(); 151 int _result; 152 try { 153 _data.writeInterfaceToken(DESCRIPTOR); 154 _data.writeString(mountPoint); 155 mRemote.transact(Stub.TRANSACTION_mountVolume, _data, _reply, 0); 156 _reply.readException(); 157 _result = _reply.readInt(); 158 } finally { 159 _reply.recycle(); 160 _data.recycle(); 161 } 162 return _result; 163 } 164 165 /** 166 * Safely unmount external storage at given mount point. The unmount 167 * is an asynchronous operation. Applications should register 168 * StorageEventListener for storage related status changes. 169 */ 170 public void unmountVolume(String mountPoint, boolean force) throws RemoteException { 171 Parcel _data = Parcel.obtain(); 172 Parcel _reply = Parcel.obtain(); 173 try { 174 _data.writeInterfaceToken(DESCRIPTOR); 175 _data.writeString(mountPoint); 176 _data.writeInt((force ? 1 : 0)); 177 mRemote.transact(Stub.TRANSACTION_unmountVolume, _data, _reply, 0); 178 _reply.readException(); 179 } finally { 180 _reply.recycle(); 181 _data.recycle(); 182 } 183 } 184 185 /** 186 * Format external storage given a mount point. Returns an int 187 * consistent with MountServiceResultCode 188 */ 189 public int formatVolume(String mountPoint) throws RemoteException { 190 Parcel _data = Parcel.obtain(); 191 Parcel _reply = Parcel.obtain(); 192 int _result; 193 try { 194 _data.writeInterfaceToken(DESCRIPTOR); 195 _data.writeString(mountPoint); 196 mRemote.transact(Stub.TRANSACTION_formatVolume, _data, _reply, 0); 197 _reply.readException(); 198 _result = _reply.readInt(); 199 } finally { 200 _reply.recycle(); 201 _data.recycle(); 202 } 203 return _result; 204 } 205 206 /** 207 * Returns an array of pids with open files on the specified path. 208 */ 209 public int[] getStorageUsers(String path) throws RemoteException { 210 Parcel _data = Parcel.obtain(); 211 Parcel _reply = Parcel.obtain(); 212 int[] _result; 213 try { 214 _data.writeInterfaceToken(DESCRIPTOR); 215 _data.writeString(path); 216 mRemote.transact(Stub.TRANSACTION_getStorageUsers, _data, _reply, 0); 217 _reply.readException(); 218 _result = _reply.createIntArray(); 219 } finally { 220 _reply.recycle(); 221 _data.recycle(); 222 } 223 return _result; 224 } 225 226 /** 227 * Gets the state of a volume via its mountpoint. 228 */ 229 public String getVolumeState(String mountPoint) throws RemoteException { 230 Parcel _data = Parcel.obtain(); 231 Parcel _reply = Parcel.obtain(); 232 String _result; 233 try { 234 _data.writeInterfaceToken(DESCRIPTOR); 235 _data.writeString(mountPoint); 236 mRemote.transact(Stub.TRANSACTION_getVolumeState, _data, _reply, 0); 237 _reply.readException(); 238 _result = _reply.readString(); 239 } finally { 240 _reply.recycle(); 241 _data.recycle(); 242 } 243 return _result; 244 } 245 246 /* 247 * Creates a secure container with the specified parameters. Returns 248 * an int consistent with MountServiceResultCode 249 */ 250 public int createSecureContainer(String id, int sizeMb, String fstype, String key, 251 int ownerUid) throws RemoteException { 252 Parcel _data = Parcel.obtain(); 253 Parcel _reply = Parcel.obtain(); 254 int _result; 255 try { 256 _data.writeInterfaceToken(DESCRIPTOR); 257 _data.writeString(id); 258 _data.writeInt(sizeMb); 259 _data.writeString(fstype); 260 _data.writeString(key); 261 _data.writeInt(ownerUid); 262 mRemote.transact(Stub.TRANSACTION_createSecureContainer, _data, _reply, 0); 263 _reply.readException(); 264 _result = _reply.readInt(); 265 } finally { 266 _reply.recycle(); 267 _data.recycle(); 268 } 269 return _result; 270 } 271 272 /* 273 * Destroy a secure container, and free up all resources associated 274 * with it. NOTE: Ensure all references are released prior to 275 * deleting. Returns an int consistent with MountServiceResultCode 276 */ 277 public int destroySecureContainer(String id, boolean force) throws RemoteException { 278 Parcel _data = Parcel.obtain(); 279 Parcel _reply = Parcel.obtain(); 280 int _result; 281 try { 282 _data.writeInterfaceToken(DESCRIPTOR); 283 _data.writeString(id); 284 _data.writeInt((force ? 1 : 0)); 285 mRemote.transact(Stub.TRANSACTION_destroySecureContainer, _data, _reply, 0); 286 _reply.readException(); 287 _result = _reply.readInt(); 288 } finally { 289 _reply.recycle(); 290 _data.recycle(); 291 } 292 return _result; 293 } 294 295 /* 296 * Finalize a container which has just been created and populated. 297 * After finalization, the container is immutable. Returns an int 298 * consistent with MountServiceResultCode 299 */ 300 public int finalizeSecureContainer(String id) throws RemoteException { 301 Parcel _data = Parcel.obtain(); 302 Parcel _reply = Parcel.obtain(); 303 int _result; 304 try { 305 _data.writeInterfaceToken(DESCRIPTOR); 306 _data.writeString(id); 307 mRemote.transact(Stub.TRANSACTION_finalizeSecureContainer, _data, _reply, 0); 308 _reply.readException(); 309 _result = _reply.readInt(); 310 } finally { 311 _reply.recycle(); 312 _data.recycle(); 313 } 314 return _result; 315 } 316 317 /* 318 * Mount a secure container with the specified key and owner UID. 319 * Returns an int consistent with MountServiceResultCode 320 */ 321 public int mountSecureContainer(String id, String key, int ownerUid) 322 throws RemoteException { 323 Parcel _data = Parcel.obtain(); 324 Parcel _reply = Parcel.obtain(); 325 int _result; 326 try { 327 _data.writeInterfaceToken(DESCRIPTOR); 328 _data.writeString(id); 329 _data.writeString(key); 330 _data.writeInt(ownerUid); 331 mRemote.transact(Stub.TRANSACTION_mountSecureContainer, _data, _reply, 0); 332 _reply.readException(); 333 _result = _reply.readInt(); 334 } finally { 335 _reply.recycle(); 336 _data.recycle(); 337 } 338 return _result; 339 } 340 341 /* 342 * Unount a secure container. Returns an int consistent with 343 * MountServiceResultCode 344 */ 345 public int unmountSecureContainer(String id, boolean force) throws RemoteException { 346 Parcel _data = Parcel.obtain(); 347 Parcel _reply = Parcel.obtain(); 348 int _result; 349 try { 350 _data.writeInterfaceToken(DESCRIPTOR); 351 _data.writeString(id); 352 _data.writeInt((force ? 1 : 0)); 353 mRemote.transact(Stub.TRANSACTION_unmountSecureContainer, _data, _reply, 0); 354 _reply.readException(); 355 _result = _reply.readInt(); 356 } finally { 357 _reply.recycle(); 358 _data.recycle(); 359 } 360 return _result; 361 } 362 363 /* 364 * Returns true if the specified container is mounted 365 */ 366 public boolean isSecureContainerMounted(String id) throws RemoteException { 367 Parcel _data = Parcel.obtain(); 368 Parcel _reply = Parcel.obtain(); 369 boolean _result; 370 try { 371 _data.writeInterfaceToken(DESCRIPTOR); 372 _data.writeString(id); 373 mRemote.transact(Stub.TRANSACTION_isSecureContainerMounted, _data, _reply, 0); 374 _reply.readException(); 375 _result = 0 != _reply.readInt(); 376 } finally { 377 _reply.recycle(); 378 _data.recycle(); 379 } 380 return _result; 381 } 382 383 /* 384 * Rename an unmounted secure container. Returns an int consistent 385 * with MountServiceResultCode 386 */ 387 public int renameSecureContainer(String oldId, String newId) throws RemoteException { 388 Parcel _data = Parcel.obtain(); 389 Parcel _reply = Parcel.obtain(); 390 int _result; 391 try { 392 _data.writeInterfaceToken(DESCRIPTOR); 393 _data.writeString(oldId); 394 _data.writeString(newId); 395 mRemote.transact(Stub.TRANSACTION_renameSecureContainer, _data, _reply, 0); 396 _reply.readException(); 397 _result = _reply.readInt(); 398 } finally { 399 _reply.recycle(); 400 _data.recycle(); 401 } 402 return _result; 403 } 404 405 /* 406 * Returns the filesystem path of a mounted secure container. 407 */ 408 public String getSecureContainerPath(String id) throws RemoteException { 409 Parcel _data = Parcel.obtain(); 410 Parcel _reply = Parcel.obtain(); 411 String _result; 412 try { 413 _data.writeInterfaceToken(DESCRIPTOR); 414 _data.writeString(id); 415 mRemote.transact(Stub.TRANSACTION_getSecureContainerPath, _data, _reply, 0); 416 _reply.readException(); 417 _result = _reply.readString(); 418 } finally { 419 _reply.recycle(); 420 _data.recycle(); 421 } 422 return _result; 423 } 424 425 /** 426 * Gets an Array of currently known secure container IDs 427 */ 428 public String[] getSecureContainerList() throws RemoteException { 429 Parcel _data = Parcel.obtain(); 430 Parcel _reply = Parcel.obtain(); 431 String[] _result; 432 try { 433 _data.writeInterfaceToken(DESCRIPTOR); 434 mRemote.transact(Stub.TRANSACTION_getSecureContainerList, _data, _reply, 0); 435 _reply.readException(); 436 _result = _reply.createStringArray(); 437 } finally { 438 _reply.recycle(); 439 _data.recycle(); 440 } 441 return _result; 442 } 443 444 /** 445 * Shuts down the MountService and gracefully unmounts all external 446 * media. Invokes call back once the shutdown is complete. 447 */ 448 public void shutdown(IMountShutdownObserver observer) 449 throws RemoteException { 450 Parcel _data = Parcel.obtain(); 451 Parcel _reply = Parcel.obtain(); 452 try { 453 _data.writeInterfaceToken(DESCRIPTOR); 454 _data.writeStrongBinder((observer != null ? observer.asBinder() : null)); 455 mRemote.transact(Stub.TRANSACTION_shutdown, _data, _reply, 0); 456 _reply.readException(); 457 } finally { 458 _reply.recycle(); 459 _data.recycle(); 460 } 461 } 462 463 /** 464 * Call into MountService by PackageManager to notify that its done 465 * processing the media status update request. 466 */ 467 public void finishMediaUpdate() throws RemoteException { 468 Parcel _data = Parcel.obtain(); 469 Parcel _reply = Parcel.obtain(); 470 try { 471 _data.writeInterfaceToken(DESCRIPTOR); 472 mRemote.transact(Stub.TRANSACTION_finishMediaUpdate, _data, _reply, 0); 473 _reply.readException(); 474 } finally { 475 _reply.recycle(); 476 _data.recycle(); 477 } 478 } 479 480 /** 481 * Mounts an Opaque Binary Blob (OBB) with the specified decryption 482 * key and only allows the calling process's UID access to the 483 * contents. MountService will call back to the supplied 484 * IObbActionListener to inform it of the terminal state of the 485 * call. 486 */ 487 public void mountObb(String filename, String key, IObbActionListener token, int nonce) 488 throws RemoteException { 489 Parcel _data = Parcel.obtain(); 490 Parcel _reply = Parcel.obtain(); 491 try { 492 _data.writeInterfaceToken(DESCRIPTOR); 493 _data.writeString(filename); 494 _data.writeString(key); 495 _data.writeStrongBinder((token != null ? token.asBinder() : null)); 496 _data.writeInt(nonce); 497 mRemote.transact(Stub.TRANSACTION_mountObb, _data, _reply, 0); 498 _reply.readException(); 499 } finally { 500 _reply.recycle(); 501 _data.recycle(); 502 } 503 } 504 505 /** 506 * Unmounts an Opaque Binary Blob (OBB). When the force flag is 507 * specified, any program using it will be forcibly killed to 508 * unmount the image. MountService will call back to the supplied 509 * IObbActionListener to inform it of the terminal state of the 510 * call. 511 */ 512 public void unmountObb(String filename, boolean force, IObbActionListener token, 513 int nonce) throws RemoteException { 514 Parcel _data = Parcel.obtain(); 515 Parcel _reply = Parcel.obtain(); 516 try { 517 _data.writeInterfaceToken(DESCRIPTOR); 518 _data.writeString(filename); 519 _data.writeInt((force ? 1 : 0)); 520 _data.writeStrongBinder((token != null ? token.asBinder() : null)); 521 _data.writeInt(nonce); 522 mRemote.transact(Stub.TRANSACTION_unmountObb, _data, _reply, 0); 523 _reply.readException(); 524 } finally { 525 _reply.recycle(); 526 _data.recycle(); 527 } 528 } 529 530 /** 531 * Checks whether the specified Opaque Binary Blob (OBB) is mounted 532 * somewhere. 533 */ 534 public boolean isObbMounted(String filename) throws RemoteException { 535 Parcel _data = Parcel.obtain(); 536 Parcel _reply = Parcel.obtain(); 537 boolean _result; 538 try { 539 _data.writeInterfaceToken(DESCRIPTOR); 540 _data.writeString(filename); 541 mRemote.transact(Stub.TRANSACTION_isObbMounted, _data, _reply, 0); 542 _reply.readException(); 543 _result = 0 != _reply.readInt(); 544 } finally { 545 _reply.recycle(); 546 _data.recycle(); 547 } 548 return _result; 549 } 550 551 /** 552 * Gets the path to the mounted Opaque Binary Blob (OBB). 553 */ 554 public String getMountedObbPath(String filename) throws RemoteException { 555 Parcel _data = Parcel.obtain(); 556 Parcel _reply = Parcel.obtain(); 557 String _result; 558 try { 559 _data.writeInterfaceToken(DESCRIPTOR); 560 _data.writeString(filename); 561 mRemote.transact(Stub.TRANSACTION_getMountedObbPath, _data, _reply, 0); 562 _reply.readException(); 563 _result = _reply.readString(); 564 } finally { 565 _reply.recycle(); 566 _data.recycle(); 567 } 568 return _result; 569 } 570 571 /** 572 * Returns whether the external storage is emulated. 573 */ 574 public boolean isExternalStorageEmulated() throws RemoteException { 575 Parcel _data = Parcel.obtain(); 576 Parcel _reply = Parcel.obtain(); 577 boolean _result; 578 try { 579 _data.writeInterfaceToken(DESCRIPTOR); 580 mRemote.transact(Stub.TRANSACTION_isExternalStorageEmulated, _data, _reply, 0); 581 _reply.readException(); 582 _result = 0 != _reply.readInt(); 583 } finally { 584 _reply.recycle(); 585 _data.recycle(); 586 } 587 return _result; 588 } 589 590 public int decryptStorage(String password) throws RemoteException { 591 Parcel _data = Parcel.obtain(); 592 Parcel _reply = Parcel.obtain(); 593 int _result; 594 try { 595 _data.writeInterfaceToken(DESCRIPTOR); 596 _data.writeString(password); 597 mRemote.transact(Stub.TRANSACTION_decryptStorage, _data, _reply, 0); 598 _reply.readException(); 599 _result = _reply.readInt(); 600 } finally { 601 _reply.recycle(); 602 _data.recycle(); 603 } 604 return _result; 605 } 606 607 public int encryptStorage(String password) throws RemoteException { 608 Parcel _data = Parcel.obtain(); 609 Parcel _reply = Parcel.obtain(); 610 int _result; 611 try { 612 _data.writeInterfaceToken(DESCRIPTOR); 613 _data.writeString(password); 614 mRemote.transact(Stub.TRANSACTION_encryptStorage, _data, _reply, 0); 615 _reply.readException(); 616 _result = _reply.readInt(); 617 } finally { 618 _reply.recycle(); 619 _data.recycle(); 620 } 621 return _result; 622 } 623 624 public int changeEncryptionPassword(String password) throws RemoteException { 625 Parcel _data = Parcel.obtain(); 626 Parcel _reply = Parcel.obtain(); 627 int _result; 628 try { 629 _data.writeInterfaceToken(DESCRIPTOR); 630 _data.writeString(password); 631 mRemote.transact(Stub.TRANSACTION_changeEncryptionPassword, _data, _reply, 0); 632 _reply.readException(); 633 _result = _reply.readInt(); 634 } finally { 635 _reply.recycle(); 636 _data.recycle(); 637 } 638 return _result; 639 } 640 641 public String[] getVolumeList() throws RemoteException { 642 Parcel _data = Parcel.obtain(); 643 Parcel _reply = Parcel.obtain(); 644 String[] _result; 645 try { 646 _data.writeInterfaceToken(DESCRIPTOR); 647 mRemote.transact(Stub.TRANSACTION_getVolumeList, _data, _reply, 0); 648 _reply.readException(); 649 _result = _reply.readStringArray(); 650 } finally { 651 _reply.recycle(); 652 _data.recycle(); 653 } 654 return _result; 655 } 656 } 657 658 private static final String DESCRIPTOR = "IMountService"; 659 660 static final int TRANSACTION_registerListener = IBinder.FIRST_CALL_TRANSACTION + 0; 661 662 static final int TRANSACTION_unregisterListener = IBinder.FIRST_CALL_TRANSACTION + 1; 663 664 static final int TRANSACTION_isUsbMassStorageConnected = IBinder.FIRST_CALL_TRANSACTION + 2; 665 666 static final int TRANSACTION_setUsbMassStorageEnabled = IBinder.FIRST_CALL_TRANSACTION + 3; 667 668 static final int TRANSACTION_isUsbMassStorageEnabled = IBinder.FIRST_CALL_TRANSACTION + 4; 669 670 static final int TRANSACTION_mountVolume = IBinder.FIRST_CALL_TRANSACTION + 5; 671 672 static final int TRANSACTION_unmountVolume = IBinder.FIRST_CALL_TRANSACTION + 6; 673 674 static final int TRANSACTION_formatVolume = IBinder.FIRST_CALL_TRANSACTION + 7; 675 676 static final int TRANSACTION_getStorageUsers = IBinder.FIRST_CALL_TRANSACTION + 8; 677 678 static final int TRANSACTION_getVolumeState = IBinder.FIRST_CALL_TRANSACTION + 9; 679 680 static final int TRANSACTION_createSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 10; 681 682 static final int TRANSACTION_finalizeSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 11; 683 684 static final int TRANSACTION_destroySecureContainer = IBinder.FIRST_CALL_TRANSACTION + 12; 685 686 static final int TRANSACTION_mountSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 13; 687 688 static final int TRANSACTION_unmountSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 14; 689 690 static final int TRANSACTION_isSecureContainerMounted = IBinder.FIRST_CALL_TRANSACTION + 15; 691 692 static final int TRANSACTION_renameSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 16; 693 694 static final int TRANSACTION_getSecureContainerPath = IBinder.FIRST_CALL_TRANSACTION + 17; 695 696 static final int TRANSACTION_getSecureContainerList = IBinder.FIRST_CALL_TRANSACTION + 18; 697 698 static final int TRANSACTION_shutdown = IBinder.FIRST_CALL_TRANSACTION + 19; 699 700 static final int TRANSACTION_finishMediaUpdate = IBinder.FIRST_CALL_TRANSACTION + 20; 701 702 static final int TRANSACTION_mountObb = IBinder.FIRST_CALL_TRANSACTION + 21; 703 704 static final int TRANSACTION_unmountObb = IBinder.FIRST_CALL_TRANSACTION + 22; 705 706 static final int TRANSACTION_isObbMounted = IBinder.FIRST_CALL_TRANSACTION + 23; 707 708 static final int TRANSACTION_getMountedObbPath = IBinder.FIRST_CALL_TRANSACTION + 24; 709 710 static final int TRANSACTION_isExternalStorageEmulated = IBinder.FIRST_CALL_TRANSACTION + 25; 711 712 static final int TRANSACTION_decryptStorage = IBinder.FIRST_CALL_TRANSACTION + 26; 713 714 static final int TRANSACTION_encryptStorage = IBinder.FIRST_CALL_TRANSACTION + 27; 715 716 static final int TRANSACTION_changeEncryptionPassword = IBinder.FIRST_CALL_TRANSACTION + 28; 717 718 static final int TRANSACTION_getVolumeList = IBinder.FIRST_CALL_TRANSACTION + 29; 719 720 /** 721 * Cast an IBinder object into an IMountService interface, generating a 722 * proxy if needed. 723 */ 724 public static IMountService asInterface(IBinder obj) { 725 if (obj == null) { 726 return null; 727 } 728 IInterface iin = obj.queryLocalInterface(DESCRIPTOR); 729 if (iin != null && iin instanceof IMountService) { 730 return (IMountService) iin; 731 } 732 return new IMountService.Stub.Proxy(obj); 733 } 734 735 /** Construct the stub at attach it to the interface. */ 736 public Stub() { 737 attachInterface(this, DESCRIPTOR); 738 } 739 740 public IBinder asBinder() { 741 return this; 742 } 743 744 @Override 745 public boolean onTransact(int code, Parcel data, Parcel reply, 746 int flags) throws RemoteException { 747 switch (code) { 748 case INTERFACE_TRANSACTION: { 749 reply.writeString(DESCRIPTOR); 750 return true; 751 } 752 case TRANSACTION_registerListener: { 753 data.enforceInterface(DESCRIPTOR); 754 IMountServiceListener listener; 755 listener = IMountServiceListener.Stub.asInterface(data.readStrongBinder()); 756 registerListener(listener); 757 reply.writeNoException(); 758 return true; 759 } 760 case TRANSACTION_unregisterListener: { 761 data.enforceInterface(DESCRIPTOR); 762 IMountServiceListener listener; 763 listener = IMountServiceListener.Stub.asInterface(data.readStrongBinder()); 764 unregisterListener(listener); 765 reply.writeNoException(); 766 return true; 767 } 768 case TRANSACTION_isUsbMassStorageConnected: { 769 data.enforceInterface(DESCRIPTOR); 770 boolean result = isUsbMassStorageConnected(); 771 reply.writeNoException(); 772 reply.writeInt((result ? 1 : 0)); 773 return true; 774 } 775 case TRANSACTION_setUsbMassStorageEnabled: { 776 data.enforceInterface(DESCRIPTOR); 777 boolean enable; 778 enable = 0 != data.readInt(); 779 setUsbMassStorageEnabled(enable); 780 reply.writeNoException(); 781 return true; 782 } 783 case TRANSACTION_isUsbMassStorageEnabled: { 784 data.enforceInterface(DESCRIPTOR); 785 boolean result = isUsbMassStorageEnabled(); 786 reply.writeNoException(); 787 reply.writeInt((result ? 1 : 0)); 788 return true; 789 } 790 case TRANSACTION_mountVolume: { 791 data.enforceInterface(DESCRIPTOR); 792 String mountPoint; 793 mountPoint = data.readString(); 794 int resultCode = mountVolume(mountPoint); 795 reply.writeNoException(); 796 reply.writeInt(resultCode); 797 return true; 798 } 799 case TRANSACTION_unmountVolume: { 800 data.enforceInterface(DESCRIPTOR); 801 String mountPoint; 802 mountPoint = data.readString(); 803 boolean force; 804 force = 0 != data.readInt(); 805 unmountVolume(mountPoint, force); 806 reply.writeNoException(); 807 return true; 808 } 809 case TRANSACTION_formatVolume: { 810 data.enforceInterface(DESCRIPTOR); 811 String mountPoint; 812 mountPoint = data.readString(); 813 int result = formatVolume(mountPoint); 814 reply.writeNoException(); 815 reply.writeInt(result); 816 return true; 817 } 818 case TRANSACTION_getStorageUsers: { 819 data.enforceInterface(DESCRIPTOR); 820 String path; 821 path = data.readString(); 822 int[] pids = getStorageUsers(path); 823 reply.writeNoException(); 824 reply.writeIntArray(pids); 825 return true; 826 } 827 case TRANSACTION_getVolumeState: { 828 data.enforceInterface(DESCRIPTOR); 829 String mountPoint; 830 mountPoint = data.readString(); 831 String state = getVolumeState(mountPoint); 832 reply.writeNoException(); 833 reply.writeString(state); 834 return true; 835 } 836 case TRANSACTION_createSecureContainer: { 837 data.enforceInterface(DESCRIPTOR); 838 String id; 839 id = data.readString(); 840 int sizeMb; 841 sizeMb = data.readInt(); 842 String fstype; 843 fstype = data.readString(); 844 String key; 845 key = data.readString(); 846 int ownerUid; 847 ownerUid = data.readInt(); 848 int resultCode = createSecureContainer(id, sizeMb, fstype, key, ownerUid); 849 reply.writeNoException(); 850 reply.writeInt(resultCode); 851 return true; 852 } 853 case TRANSACTION_finalizeSecureContainer: { 854 data.enforceInterface(DESCRIPTOR); 855 String id; 856 id = data.readString(); 857 int resultCode = finalizeSecureContainer(id); 858 reply.writeNoException(); 859 reply.writeInt(resultCode); 860 return true; 861 } 862 case TRANSACTION_destroySecureContainer: { 863 data.enforceInterface(DESCRIPTOR); 864 String id; 865 id = data.readString(); 866 boolean force; 867 force = 0 != data.readInt(); 868 int resultCode = destroySecureContainer(id, force); 869 reply.writeNoException(); 870 reply.writeInt(resultCode); 871 return true; 872 } 873 case TRANSACTION_mountSecureContainer: { 874 data.enforceInterface(DESCRIPTOR); 875 String id; 876 id = data.readString(); 877 String key; 878 key = data.readString(); 879 int ownerUid; 880 ownerUid = data.readInt(); 881 int resultCode = mountSecureContainer(id, key, ownerUid); 882 reply.writeNoException(); 883 reply.writeInt(resultCode); 884 return true; 885 } 886 case TRANSACTION_unmountSecureContainer: { 887 data.enforceInterface(DESCRIPTOR); 888 String id; 889 id = data.readString(); 890 boolean force; 891 force = 0 != data.readInt(); 892 int resultCode = unmountSecureContainer(id, force); 893 reply.writeNoException(); 894 reply.writeInt(resultCode); 895 return true; 896 } 897 case TRANSACTION_isSecureContainerMounted: { 898 data.enforceInterface(DESCRIPTOR); 899 String id; 900 id = data.readString(); 901 boolean status = isSecureContainerMounted(id); 902 reply.writeNoException(); 903 reply.writeInt((status ? 1 : 0)); 904 return true; 905 } 906 case TRANSACTION_renameSecureContainer: { 907 data.enforceInterface(DESCRIPTOR); 908 String oldId; 909 oldId = data.readString(); 910 String newId; 911 newId = data.readString(); 912 int resultCode = renameSecureContainer(oldId, newId); 913 reply.writeNoException(); 914 reply.writeInt(resultCode); 915 return true; 916 } 917 case TRANSACTION_getSecureContainerPath: { 918 data.enforceInterface(DESCRIPTOR); 919 String id; 920 id = data.readString(); 921 String path = getSecureContainerPath(id); 922 reply.writeNoException(); 923 reply.writeString(path); 924 return true; 925 } 926 case TRANSACTION_getSecureContainerList: { 927 data.enforceInterface(DESCRIPTOR); 928 String[] ids = getSecureContainerList(); 929 reply.writeNoException(); 930 reply.writeStringArray(ids); 931 return true; 932 } 933 case TRANSACTION_shutdown: { 934 data.enforceInterface(DESCRIPTOR); 935 IMountShutdownObserver observer; 936 observer = IMountShutdownObserver.Stub.asInterface(data 937 .readStrongBinder()); 938 shutdown(observer); 939 reply.writeNoException(); 940 return true; 941 } 942 case TRANSACTION_finishMediaUpdate: { 943 data.enforceInterface(DESCRIPTOR); 944 finishMediaUpdate(); 945 reply.writeNoException(); 946 return true; 947 } 948 case TRANSACTION_mountObb: { 949 data.enforceInterface(DESCRIPTOR); 950 String filename; 951 filename = data.readString(); 952 String key; 953 key = data.readString(); 954 IObbActionListener observer; 955 observer = IObbActionListener.Stub.asInterface(data.readStrongBinder()); 956 int nonce; 957 nonce = data.readInt(); 958 mountObb(filename, key, observer, nonce); 959 reply.writeNoException(); 960 return true; 961 } 962 case TRANSACTION_unmountObb: { 963 data.enforceInterface(DESCRIPTOR); 964 String filename; 965 filename = data.readString(); 966 boolean force; 967 force = 0 != data.readInt(); 968 IObbActionListener observer; 969 observer = IObbActionListener.Stub.asInterface(data.readStrongBinder()); 970 int nonce; 971 nonce = data.readInt(); 972 unmountObb(filename, force, observer, nonce); 973 reply.writeNoException(); 974 return true; 975 } 976 case TRANSACTION_isObbMounted: { 977 data.enforceInterface(DESCRIPTOR); 978 String filename; 979 filename = data.readString(); 980 boolean status = isObbMounted(filename); 981 reply.writeNoException(); 982 reply.writeInt((status ? 1 : 0)); 983 return true; 984 } 985 case TRANSACTION_getMountedObbPath: { 986 data.enforceInterface(DESCRIPTOR); 987 String filename; 988 filename = data.readString(); 989 String mountedPath = getMountedObbPath(filename); 990 reply.writeNoException(); 991 reply.writeString(mountedPath); 992 return true; 993 } 994 case TRANSACTION_isExternalStorageEmulated: { 995 data.enforceInterface(DESCRIPTOR); 996 boolean emulated = isExternalStorageEmulated(); 997 reply.writeNoException(); 998 reply.writeInt(emulated ? 1 : 0); 999 return true; 1000 } 1001 case TRANSACTION_decryptStorage: { 1002 data.enforceInterface(DESCRIPTOR); 1003 String password = data.readString(); 1004 int result = decryptStorage(password); 1005 reply.writeNoException(); 1006 reply.writeInt(result); 1007 return true; 1008 } 1009 case TRANSACTION_encryptStorage: { 1010 data.enforceInterface(DESCRIPTOR); 1011 String password = data.readString(); 1012 int result = encryptStorage(password); 1013 reply.writeNoException(); 1014 reply.writeInt(result); 1015 return true; 1016 } 1017 case TRANSACTION_changeEncryptionPassword: { 1018 data.enforceInterface(DESCRIPTOR); 1019 String password = data.readString(); 1020 int result = changeEncryptionPassword(password); 1021 reply.writeNoException(); 1022 reply.writeInt(result); 1023 return true; 1024 } 1025 case TRANSACTION_getVolumeList: { 1026 data.enforceInterface(DESCRIPTOR); 1027 String[] result = getVolumeList(); 1028 reply.writeNoException(); 1029 reply.writeStringArray(result); 1030 return true; 1031 } 1032 } 1033 return super.onTransact(code, data, reply, flags); 1034 } 1035 } 1036 1037 /* 1038 * Creates a secure container with the specified parameters. Returns an int 1039 * consistent with MountServiceResultCode 1040 */ 1041 public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid) 1042 throws RemoteException; 1043 1044 /* 1045 * Destroy a secure container, and free up all resources associated with it. 1046 * NOTE: Ensure all references are released prior to deleting. Returns an 1047 * int consistent with MountServiceResultCode 1048 */ 1049 public int destroySecureContainer(String id, boolean force) throws RemoteException; 1050 1051 /* 1052 * Finalize a container which has just been created and populated. After 1053 * finalization, the container is immutable. Returns an int consistent with 1054 * MountServiceResultCode 1055 */ 1056 public int finalizeSecureContainer(String id) throws RemoteException; 1057 1058 /** 1059 * Call into MountService by PackageManager to notify that its done 1060 * processing the media status update request. 1061 */ 1062 public void finishMediaUpdate() throws RemoteException; 1063 1064 /** 1065 * Format external storage given a mount point. Returns an int consistent 1066 * with MountServiceResultCode 1067 */ 1068 public int formatVolume(String mountPoint) throws RemoteException; 1069 1070 /** 1071 * Gets the path to the mounted Opaque Binary Blob (OBB). 1072 */ 1073 public String getMountedObbPath(String filename) throws RemoteException; 1074 1075 /** 1076 * Gets an Array of currently known secure container IDs 1077 */ 1078 public String[] getSecureContainerList() throws RemoteException; 1079 1080 /* 1081 * Returns the filesystem path of a mounted secure container. 1082 */ 1083 public String getSecureContainerPath(String id) throws RemoteException; 1084 1085 /** 1086 * Returns an array of pids with open files on the specified path. 1087 */ 1088 public int[] getStorageUsers(String path) throws RemoteException; 1089 1090 /** 1091 * Gets the state of a volume via its mountpoint. 1092 */ 1093 public String getVolumeState(String mountPoint) throws RemoteException; 1094 1095 /** 1096 * Checks whether the specified Opaque Binary Blob (OBB) is mounted 1097 * somewhere. 1098 */ 1099 public boolean isObbMounted(String filename) throws RemoteException; 1100 1101 /* 1102 * Returns true if the specified container is mounted 1103 */ 1104 public boolean isSecureContainerMounted(String id) throws RemoteException; 1105 1106 /** 1107 * Returns true if a USB mass storage host is connected 1108 */ 1109 public boolean isUsbMassStorageConnected() throws RemoteException; 1110 1111 /** 1112 * Returns true if a USB mass storage host is enabled (media is shared) 1113 */ 1114 public boolean isUsbMassStorageEnabled() throws RemoteException; 1115 1116 /** 1117 * Mounts an Opaque Binary Blob (OBB) with the specified decryption key and 1118 * only allows the calling process's UID access to the contents. 1119 * MountService will call back to the supplied IObbActionListener to inform 1120 * it of the terminal state of the call. 1121 */ 1122 public void mountObb(String filename, String key, IObbActionListener token, int nonce) 1123 throws RemoteException; 1124 1125 /* 1126 * Mount a secure container with the specified key and owner UID. Returns an 1127 * int consistent with MountServiceResultCode 1128 */ 1129 public int mountSecureContainer(String id, String key, int ownerUid) throws RemoteException; 1130 1131 /** 1132 * Mount external storage at given mount point. Returns an int consistent 1133 * with MountServiceResultCode 1134 */ 1135 public int mountVolume(String mountPoint) throws RemoteException; 1136 1137 /** 1138 * Registers an IMountServiceListener for receiving async notifications. 1139 */ 1140 public void registerListener(IMountServiceListener listener) throws RemoteException; 1141 1142 /* 1143 * Rename an unmounted secure container. Returns an int consistent with 1144 * MountServiceResultCode 1145 */ 1146 public int renameSecureContainer(String oldId, String newId) throws RemoteException; 1147 1148 /** 1149 * Enables / disables USB mass storage. The caller should check actual 1150 * status of enabling/disabling USB mass storage via StorageEventListener. 1151 */ 1152 public void setUsbMassStorageEnabled(boolean enable) throws RemoteException; 1153 1154 /** 1155 * Shuts down the MountService and gracefully unmounts all external media. 1156 * Invokes call back once the shutdown is complete. 1157 */ 1158 public void shutdown(IMountShutdownObserver observer) throws RemoteException; 1159 1160 /** 1161 * Unmounts an Opaque Binary Blob (OBB). When the force flag is specified, 1162 * any program using it will be forcibly killed to unmount the image. 1163 * MountService will call back to the supplied IObbActionListener to inform 1164 * it of the terminal state of the call. 1165 */ 1166 public void unmountObb(String filename, boolean force, IObbActionListener token, int nonce) 1167 throws RemoteException; 1168 1169 /* 1170 * Unount a secure container. Returns an int consistent with 1171 * MountServiceResultCode 1172 */ 1173 public int unmountSecureContainer(String id, boolean force) throws RemoteException; 1174 1175 /** 1176 * Safely unmount external storage at given mount point. The unmount is an 1177 * asynchronous operation. Applications should register StorageEventListener 1178 * for storage related status changes. 1179 */ 1180 public void unmountVolume(String mountPoint, boolean force) throws RemoteException; 1181 1182 /** 1183 * Unregisters an IMountServiceListener 1184 */ 1185 public void unregisterListener(IMountServiceListener listener) throws RemoteException; 1186 1187 /** 1188 * Returns whether or not the external storage is emulated. 1189 */ 1190 public boolean isExternalStorageEmulated() throws RemoteException; 1191 1192 /** 1193 * Decrypts any encrypted volumes. 1194 */ 1195 public int decryptStorage(String password) throws RemoteException; 1196 1197 /** 1198 * Encrypts storage. 1199 */ 1200 public int encryptStorage(String password) throws RemoteException; 1201 1202 /** 1203 * Changes the encryption password. 1204 */ 1205 public int changeEncryptionPassword(String password) throws RemoteException; 1206 1207 /** 1208 * Returns list of all mountable volumes. 1209 */ 1210 public String[] getVolumeList() throws RemoteException; 1211} 1212