AssetManager.java revision 41a5ed7cd9f56d955a797a485c11ae5e7ccfb094
1/* 2 * Copyright (C) 2006 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.content.res; 18 19import android.os.ParcelFileDescriptor; 20import android.util.Config; 21import android.util.Log; 22import android.util.TypedValue; 23 24import java.io.FileNotFoundException; 25import java.io.IOException; 26import java.io.InputStream; 27import java.util.HashMap; 28 29/** 30 * Provides access to an application's raw asset files; see {@link Resources} 31 * for the way most applications will want to retrieve their resource data. 32 * This class presents a lower-level API that allows you to open and read raw 33 * files that have been bundled with the application as a simple stream of 34 * bytes. 35 */ 36public final class AssetManager { 37 /* modes used when opening an asset */ 38 39 /** 40 * Mode for {@link #open(String, int)}: no specific information about how 41 * data will be accessed. 42 */ 43 public static final int ACCESS_UNKNOWN = 0; 44 /** 45 * Mode for {@link #open(String, int)}: Read chunks, and seek forward and 46 * backward. 47 */ 48 public static final int ACCESS_RANDOM = 1; 49 /** 50 * Mode for {@link #open(String, int)}: Read sequentially, with an 51 * occasional forward seek. 52 */ 53 public static final int ACCESS_STREAMING = 2; 54 /** 55 * Mode for {@link #open(String, int)}: Attempt to load contents into 56 * memory, for fast small reads. 57 */ 58 public static final int ACCESS_BUFFER = 3; 59 60 private static final String TAG = "AssetManager"; 61 private static final boolean localLOGV = Config.LOGV || false; 62 63 private static final boolean DEBUG_REFS = false; 64 65 private static final Object sSync = new Object(); 66 private static AssetManager sSystem = null; 67 68 private final TypedValue mValue = new TypedValue(); 69 private final long[] mOffsets = new long[2]; 70 71 // For communication with native code. 72 private int mObject; 73 private int mNObject; // used by the NDK 74 75 private StringBlock mStringBlocks[] = null; 76 77 private int mNumRefs = 1; 78 private boolean mOpen = true; 79 private HashMap<Integer, RuntimeException> mRefStacks; 80 81 /** 82 * Create a new AssetManager containing only the basic system assets. 83 * Applications will not generally use this method, instead retrieving the 84 * appropriate asset manager with {@link Resources#getAssets}. Not for 85 * use by applications. 86 * {@hide} 87 */ 88 public AssetManager() { 89 synchronized (this) { 90 if (DEBUG_REFS) { 91 mNumRefs = 0; 92 incRefsLocked(this.hashCode()); 93 } 94 init(); 95 if (localLOGV) Log.v(TAG, "New asset manager: " + this); 96 ensureSystemAssets(); 97 } 98 } 99 100 private static void ensureSystemAssets() { 101 synchronized (sSync) { 102 if (sSystem == null) { 103 AssetManager system = new AssetManager(true); 104 system.makeStringBlocks(false); 105 sSystem = system; 106 } 107 } 108 } 109 110 private AssetManager(boolean isSystem) { 111 if (DEBUG_REFS) { 112 synchronized (this) { 113 mNumRefs = 0; 114 incRefsLocked(this.hashCode()); 115 } 116 } 117 init(); 118 if (localLOGV) Log.v(TAG, "New asset manager: " + this); 119 } 120 121 /** 122 * Return a global shared asset manager that provides access to only 123 * system assets (no application assets). 124 * {@hide} 125 */ 126 public static AssetManager getSystem() { 127 ensureSystemAssets(); 128 return sSystem; 129 } 130 131 /** 132 * Close this asset manager. 133 */ 134 public void close() { 135 synchronized(this) { 136 //System.out.println("Release: num=" + mNumRefs 137 // + ", released=" + mReleased); 138 if (mOpen) { 139 mOpen = false; 140 decRefsLocked(this.hashCode()); 141 } 142 } 143 } 144 145 /** 146 * Retrieve the string value associated with a particular resource 147 * identifier for the current configuration / skin. 148 */ 149 /*package*/ final CharSequence getResourceText(int ident) { 150 synchronized (this) { 151 TypedValue tmpValue = mValue; 152 int block = loadResourceValue(ident, tmpValue, true); 153 if (block >= 0) { 154 if (tmpValue.type == TypedValue.TYPE_STRING) { 155 return mStringBlocks[block].get(tmpValue.data); 156 } 157 return tmpValue.coerceToString(); 158 } 159 } 160 return null; 161 } 162 163 /** 164 * Retrieve the string value associated with a particular resource 165 * identifier for the current configuration / skin. 166 */ 167 /*package*/ final CharSequence getResourceBagText(int ident, int bagEntryId) { 168 synchronized (this) { 169 TypedValue tmpValue = mValue; 170 int block = loadResourceBagValue(ident, bagEntryId, tmpValue, true); 171 if (block >= 0) { 172 if (tmpValue.type == TypedValue.TYPE_STRING) { 173 return mStringBlocks[block].get(tmpValue.data); 174 } 175 return tmpValue.coerceToString(); 176 } 177 } 178 return null; 179 } 180 181 /** 182 * Retrieve the string array associated with a particular resource 183 * identifier. 184 * @param id Resource id of the string array 185 */ 186 /*package*/ final String[] getResourceStringArray(final int id) { 187 String[] retArray = getArrayStringResource(id); 188 return retArray; 189 } 190 191 192 /*package*/ final boolean getResourceValue(int ident, 193 TypedValue outValue, 194 boolean resolveRefs) 195 { 196 int block = loadResourceValue(ident, outValue, resolveRefs); 197 if (block >= 0) { 198 if (outValue.type != TypedValue.TYPE_STRING) { 199 return true; 200 } 201 outValue.string = mStringBlocks[block].get(outValue.data); 202 return true; 203 } 204 return false; 205 } 206 207 /** 208 * Retrieve the text array associated with a particular resource 209 * identifier. 210 * @param id Resource id of the string array 211 */ 212 /*package*/ final CharSequence[] getResourceTextArray(final int id) { 213 int[] rawInfoArray = getArrayStringInfo(id); 214 int rawInfoArrayLen = rawInfoArray.length; 215 final int infoArrayLen = rawInfoArrayLen / 2; 216 int block; 217 int index; 218 CharSequence[] retArray = new CharSequence[infoArrayLen]; 219 for (int i = 0, j = 0; i < rawInfoArrayLen; i = i + 2, j++) { 220 block = rawInfoArray[i]; 221 index = rawInfoArray[i + 1]; 222 retArray[j] = index >= 0 ? mStringBlocks[block].get(index) : null; 223 } 224 return retArray; 225 } 226 227 /*package*/ final boolean getThemeValue(int theme, int ident, 228 TypedValue outValue, boolean resolveRefs) { 229 int block = loadThemeAttributeValue(theme, ident, outValue, resolveRefs); 230 if (block >= 0) { 231 if (outValue.type != TypedValue.TYPE_STRING) { 232 return true; 233 } 234 StringBlock[] blocks = mStringBlocks; 235 if (blocks == null) { 236 ensureStringBlocks(); 237 blocks = mStringBlocks; 238 } 239 outValue.string = blocks[block].get(outValue.data); 240 return true; 241 } 242 return false; 243 } 244 245 /*package*/ final void ensureStringBlocks() { 246 if (mStringBlocks == null) { 247 synchronized (this) { 248 if (mStringBlocks == null) { 249 makeStringBlocks(true); 250 } 251 } 252 } 253 } 254 255 private final void makeStringBlocks(boolean copyFromSystem) { 256 final int sysNum = copyFromSystem ? sSystem.mStringBlocks.length : 0; 257 final int num = getStringBlockCount(); 258 mStringBlocks = new StringBlock[num]; 259 if (localLOGV) Log.v(TAG, "Making string blocks for " + this 260 + ": " + num); 261 for (int i=0; i<num; i++) { 262 if (i < sysNum) { 263 mStringBlocks[i] = sSystem.mStringBlocks[i]; 264 } else { 265 mStringBlocks[i] = new StringBlock(getNativeStringBlock(i), true); 266 } 267 } 268 } 269 270 /*package*/ final CharSequence getPooledString(int block, int id) { 271 //System.out.println("Get pooled: block=" + block 272 // + ", id=#" + Integer.toHexString(id) 273 // + ", blocks=" + mStringBlocks); 274 return mStringBlocks[block-1].get(id); 275 } 276 277 /** 278 * Open an asset using ACCESS_STREAMING mode. This provides access to 279 * files that have been bundled with an application as assets -- that is, 280 * files placed in to the "assets" directory. 281 * 282 * @param fileName The name of the asset to open. This name can be 283 * hierarchical. 284 * 285 * @see #open(String, int) 286 * @see #list 287 */ 288 public final InputStream open(String fileName) throws IOException { 289 return open(fileName, ACCESS_STREAMING); 290 } 291 292 /** 293 * Open an asset using an explicit access mode, returning an InputStream to 294 * read its contents. This provides access to files that have been bundled 295 * with an application as assets -- that is, files placed in to the 296 * "assets" directory. 297 * 298 * @param fileName The name of the asset to open. This name can be 299 * hierarchical. 300 * @param accessMode Desired access mode for retrieving the data. 301 * 302 * @see #ACCESS_UNKNOWN 303 * @see #ACCESS_STREAMING 304 * @see #ACCESS_RANDOM 305 * @see #ACCESS_BUFFER 306 * @see #open(String) 307 * @see #list 308 */ 309 public final InputStream open(String fileName, int accessMode) 310 throws IOException { 311 synchronized (this) { 312 if (!mOpen) { 313 throw new RuntimeException("Assetmanager has been closed"); 314 } 315 int asset = openAsset(fileName, accessMode); 316 if (asset != 0) { 317 AssetInputStream res = new AssetInputStream(asset); 318 incRefsLocked(res.hashCode()); 319 return res; 320 } 321 } 322 throw new FileNotFoundException("Asset file: " + fileName); 323 } 324 325 public final AssetFileDescriptor openFd(String fileName) 326 throws IOException { 327 synchronized (this) { 328 if (!mOpen) { 329 throw new RuntimeException("Assetmanager has been closed"); 330 } 331 ParcelFileDescriptor pfd = openAssetFd(fileName, mOffsets); 332 if (pfd != null) { 333 return new AssetFileDescriptor(pfd, mOffsets[0], mOffsets[1]); 334 } 335 } 336 throw new FileNotFoundException("Asset file: " + fileName); 337 } 338 339 /** 340 * Return a String array of all the assets at the given path. 341 * 342 * @param path A relative path within the assets, i.e., "docs/home.html". 343 * 344 * @return String[] Array of strings, one for each asset. These file 345 * names are relative to 'path'. You can open the file by 346 * concatenating 'path' and a name in the returned string (via 347 * File) and passing that to open(). 348 * 349 * @see #open 350 */ 351 public native final String[] list(String path) 352 throws IOException; 353 354 /** 355 * {@hide} 356 * Open a non-asset file as an asset using ACCESS_STREAMING mode. This 357 * provides direct access to all of the files included in an application 358 * package (not only its assets). Applications should not normally use 359 * this. 360 * 361 * @see #open(String) 362 */ 363 public final InputStream openNonAsset(String fileName) throws IOException { 364 return openNonAsset(0, fileName, ACCESS_STREAMING); 365 } 366 367 /** 368 * {@hide} 369 * Open a non-asset file as an asset using a specific access mode. This 370 * provides direct access to all of the files included in an application 371 * package (not only its assets). Applications should not normally use 372 * this. 373 * 374 * @see #open(String, int) 375 */ 376 public final InputStream openNonAsset(String fileName, int accessMode) 377 throws IOException { 378 return openNonAsset(0, fileName, accessMode); 379 } 380 381 /** 382 * {@hide} 383 * Open a non-asset in a specified package. Not for use by applications. 384 * 385 * @param cookie Identifier of the package to be opened. 386 * @param fileName Name of the asset to retrieve. 387 */ 388 public final InputStream openNonAsset(int cookie, String fileName) 389 throws IOException { 390 return openNonAsset(cookie, fileName, ACCESS_STREAMING); 391 } 392 393 /** 394 * {@hide} 395 * Open a non-asset in a specified package. Not for use by applications. 396 * 397 * @param cookie Identifier of the package to be opened. 398 * @param fileName Name of the asset to retrieve. 399 * @param accessMode Desired access mode for retrieving the data. 400 */ 401 public final InputStream openNonAsset(int cookie, String fileName, int accessMode) 402 throws IOException { 403 synchronized (this) { 404 if (!mOpen) { 405 throw new RuntimeException("Assetmanager has been closed"); 406 } 407 int asset = openNonAssetNative(cookie, fileName, accessMode); 408 if (asset != 0) { 409 AssetInputStream res = new AssetInputStream(asset); 410 incRefsLocked(res.hashCode()); 411 return res; 412 } 413 } 414 throw new FileNotFoundException("Asset absolute file: " + fileName); 415 } 416 417 public final AssetFileDescriptor openNonAssetFd(String fileName) 418 throws IOException { 419 return openNonAssetFd(0, fileName); 420 } 421 422 public final AssetFileDescriptor openNonAssetFd(int cookie, 423 String fileName) throws IOException { 424 synchronized (this) { 425 if (!mOpen) { 426 throw new RuntimeException("Assetmanager has been closed"); 427 } 428 ParcelFileDescriptor pfd = openNonAssetFdNative(cookie, 429 fileName, mOffsets); 430 if (pfd != null) { 431 return new AssetFileDescriptor(pfd, mOffsets[0], mOffsets[1]); 432 } 433 } 434 throw new FileNotFoundException("Asset absolute file: " + fileName); 435 } 436 437 /** 438 * Retrieve a parser for a compiled XML file. 439 * 440 * @param fileName The name of the file to retrieve. 441 */ 442 public final XmlResourceParser openXmlResourceParser(String fileName) 443 throws IOException { 444 return openXmlResourceParser(0, fileName); 445 } 446 447 /** 448 * Retrieve a parser for a compiled XML file. 449 * 450 * @param cookie Identifier of the package to be opened. 451 * @param fileName The name of the file to retrieve. 452 */ 453 public final XmlResourceParser openXmlResourceParser(int cookie, 454 String fileName) throws IOException { 455 XmlBlock block = openXmlBlockAsset(cookie, fileName); 456 XmlResourceParser rp = block.newParser(); 457 block.close(); 458 return rp; 459 } 460 461 /** 462 * {@hide} 463 * Retrieve a non-asset as a compiled XML file. Not for use by 464 * applications. 465 * 466 * @param fileName The name of the file to retrieve. 467 */ 468 /*package*/ final XmlBlock openXmlBlockAsset(String fileName) 469 throws IOException { 470 return openXmlBlockAsset(0, fileName); 471 } 472 473 /** 474 * {@hide} 475 * Retrieve a non-asset as a compiled XML file. Not for use by 476 * applications. 477 * 478 * @param cookie Identifier of the package to be opened. 479 * @param fileName Name of the asset to retrieve. 480 */ 481 /*package*/ final XmlBlock openXmlBlockAsset(int cookie, String fileName) 482 throws IOException { 483 synchronized (this) { 484 if (!mOpen) { 485 throw new RuntimeException("Assetmanager has been closed"); 486 } 487 int xmlBlock = openXmlAssetNative(cookie, fileName); 488 if (xmlBlock != 0) { 489 XmlBlock res = new XmlBlock(this, xmlBlock); 490 incRefsLocked(res.hashCode()); 491 return res; 492 } 493 } 494 throw new FileNotFoundException("Asset XML file: " + fileName); 495 } 496 497 /*package*/ void xmlBlockGone(int id) { 498 synchronized (this) { 499 decRefsLocked(id); 500 } 501 } 502 503 /*package*/ final int createTheme() { 504 synchronized (this) { 505 if (!mOpen) { 506 throw new RuntimeException("Assetmanager has been closed"); 507 } 508 int res = newTheme(); 509 incRefsLocked(res); 510 return res; 511 } 512 } 513 514 /*package*/ final void releaseTheme(int theme) { 515 synchronized (this) { 516 deleteTheme(theme); 517 decRefsLocked(theme); 518 } 519 } 520 521 protected void finalize() throws Throwable { 522 try { 523 if (DEBUG_REFS && mNumRefs != 0) { 524 Log.w(TAG, "AssetManager " + this 525 + " finalized with non-zero refs: " + mNumRefs); 526 if (mRefStacks != null) { 527 for (RuntimeException e : mRefStacks.values()) { 528 Log.w(TAG, "Reference from here", e); 529 } 530 } 531 } 532 destroy(); 533 } finally { 534 super.finalize(); 535 } 536 } 537 538 public final class AssetInputStream extends InputStream { 539 public final int getAssetInt() { 540 return mAsset; 541 } 542 private AssetInputStream(int asset) 543 { 544 mAsset = asset; 545 mLength = getAssetLength(asset); 546 } 547 public final int read() throws IOException { 548 return readAssetChar(mAsset); 549 } 550 public final boolean markSupported() { 551 return true; 552 } 553 public final int available() throws IOException { 554 long len = getAssetRemainingLength(mAsset); 555 return len > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)len; 556 } 557 public final void close() throws IOException { 558 synchronized (AssetManager.this) { 559 if (mAsset != 0) { 560 destroyAsset(mAsset); 561 mAsset = 0; 562 decRefsLocked(hashCode()); 563 } 564 } 565 } 566 public final void mark(int readlimit) { 567 mMarkPos = seekAsset(mAsset, 0, 0); 568 } 569 public final void reset() throws IOException { 570 seekAsset(mAsset, mMarkPos, -1); 571 } 572 public final int read(byte[] b) throws IOException { 573 return readAsset(mAsset, b, 0, b.length); 574 } 575 public final int read(byte[] b, int off, int len) throws IOException { 576 return readAsset(mAsset, b, off, len); 577 } 578 public final long skip(long n) throws IOException { 579 long pos = seekAsset(mAsset, 0, 0); 580 if ((pos+n) > mLength) { 581 n = mLength-pos; 582 } 583 if (n > 0) { 584 seekAsset(mAsset, n, 0); 585 } 586 return n; 587 } 588 589 protected void finalize() throws Throwable 590 { 591 close(); 592 } 593 594 private int mAsset; 595 private long mLength; 596 private long mMarkPos; 597 } 598 599 /** 600 * Add an additional set of assets to the asset manager. This can be 601 * either a directory or ZIP file. Not for use by applications. Returns 602 * the cookie of the added asset, or 0 on failure. 603 * {@hide} 604 */ 605 public native final int addAssetPath(String path); 606 607 /** 608 * Add multiple sets of assets to the asset manager at once. See 609 * {@link #addAssetPath(String)} for more information. Returns array of 610 * cookies for each added asset with 0 indicating failure, or null if 611 * the input array of paths is null. 612 * {@hide} 613 */ 614 public final int[] addAssetPaths(String[] paths) { 615 if (paths == null) { 616 return null; 617 } 618 619 int[] cookies = new int[paths.length]; 620 for (int i = 0; i < paths.length; i++) { 621 cookies[i] = addAssetPath(paths[i]); 622 } 623 624 return cookies; 625 } 626 627 /** 628 * Determine whether the state in this asset manager is up-to-date with 629 * the files on the filesystem. If false is returned, you need to 630 * instantiate a new AssetManager class to see the new data. 631 * {@hide} 632 */ 633 public native final boolean isUpToDate(); 634 635 /** 636 * Change the locale being used by this asset manager. Not for use by 637 * applications. 638 * {@hide} 639 */ 640 public native final void setLocale(String locale); 641 642 /** 643 * Get the locales that this asset manager contains data for. 644 */ 645 public native final String[] getLocales(); 646 647 /** 648 * Change the configuation used when retrieving resources. Not for use by 649 * applications. 650 * {@hide} 651 */ 652 public native final void setConfiguration(int mcc, int mnc, String locale, 653 int orientation, int touchscreen, int density, int keyboard, 654 int keyboardHidden, int navigation, int screenWidth, int screenHeight, 655 int screenLayout, int uiMode, int majorVersion); 656 657 /** 658 * Retrieve the resource identifier for the given resource name. 659 */ 660 /*package*/ native final int getResourceIdentifier(String type, 661 String name, 662 String defPackage); 663 664 /*package*/ native final String getResourceName(int resid); 665 /*package*/ native final String getResourcePackageName(int resid); 666 /*package*/ native final String getResourceTypeName(int resid); 667 /*package*/ native final String getResourceEntryName(int resid); 668 669 private native final int openAsset(String fileName, int accessMode); 670 private final native ParcelFileDescriptor openAssetFd(String fileName, 671 long[] outOffsets) throws IOException; 672 private native final int openNonAssetNative(int cookie, String fileName, 673 int accessMode); 674 private native ParcelFileDescriptor openNonAssetFdNative(int cookie, 675 String fileName, long[] outOffsets) throws IOException; 676 private native final void destroyAsset(int asset); 677 private native final int readAssetChar(int asset); 678 private native final int readAsset(int asset, byte[] b, int off, int len); 679 private native final long seekAsset(int asset, long offset, int whence); 680 private native final long getAssetLength(int asset); 681 private native final long getAssetRemainingLength(int asset); 682 683 /** Returns true if the resource was found, filling in mRetStringBlock and 684 * mRetData. */ 685 private native final int loadResourceValue(int ident, TypedValue outValue, 686 boolean resolve); 687 /** Returns true if the resource was found, filling in mRetStringBlock and 688 * mRetData. */ 689 private native final int loadResourceBagValue(int ident, int bagEntryId, TypedValue outValue, 690 boolean resolve); 691 /*package*/ static final int STYLE_NUM_ENTRIES = 6; 692 /*package*/ static final int STYLE_TYPE = 0; 693 /*package*/ static final int STYLE_DATA = 1; 694 /*package*/ static final int STYLE_ASSET_COOKIE = 2; 695 /*package*/ static final int STYLE_RESOURCE_ID = 3; 696 /*package*/ static final int STYLE_CHANGING_CONFIGURATIONS = 4; 697 /*package*/ static final int STYLE_DENSITY = 5; 698 /*package*/ native static final boolean applyStyle(int theme, 699 int defStyleAttr, int defStyleRes, int xmlParser, 700 int[] inAttrs, int[] outValues, int[] outIndices); 701 /*package*/ native final boolean retrieveAttributes( 702 int xmlParser, int[] inAttrs, int[] outValues, int[] outIndices); 703 /*package*/ native final int getArraySize(int resource); 704 /*package*/ native final int retrieveArray(int resource, int[] outValues); 705 private native final int getStringBlockCount(); 706 private native final int getNativeStringBlock(int block); 707 708 /** 709 * {@hide} 710 */ 711 public native final String getCookieName(int cookie); 712 713 /** 714 * {@hide} 715 */ 716 public native static final int getGlobalAssetCount(); 717 718 /** 719 * {@hide} 720 */ 721 public native static final String getAssetAllocations(); 722 723 /** 724 * {@hide} 725 */ 726 public native static final int getGlobalAssetManagerCount(); 727 728 private native final int newTheme(); 729 private native final void deleteTheme(int theme); 730 /*package*/ native static final void applyThemeStyle(int theme, int styleRes, boolean force); 731 /*package*/ native static final void copyTheme(int dest, int source); 732 /*package*/ native static final int loadThemeAttributeValue(int theme, int ident, 733 TypedValue outValue, 734 boolean resolve); 735 /*package*/ native static final void dumpTheme(int theme, int priority, String tag, String prefix); 736 737 private native final int openXmlAssetNative(int cookie, String fileName); 738 739 private native final String[] getArrayStringResource(int arrayRes); 740 private native final int[] getArrayStringInfo(int arrayRes); 741 /*package*/ native final int[] getArrayIntResource(int arrayRes); 742 743 private native final void init(); 744 private native final void destroy(); 745 746 private final void incRefsLocked(int id) { 747 if (DEBUG_REFS) { 748 if (mRefStacks == null) { 749 mRefStacks = new HashMap<Integer, RuntimeException>(); 750 RuntimeException ex = new RuntimeException(); 751 ex.fillInStackTrace(); 752 mRefStacks.put(this.hashCode(), ex); 753 } 754 } 755 mNumRefs++; 756 } 757 758 private final void decRefsLocked(int id) { 759 if (DEBUG_REFS && mRefStacks != null) { 760 mRefStacks.remove(id); 761 } 762 mNumRefs--; 763 //System.out.println("Dec streams: mNumRefs=" + mNumRefs 764 // + " mReleased=" + mReleased); 765 if (mNumRefs == 0) { 766 destroy(); 767 } 768 } 769} 770