44import android .content .SharedPreferences ;
55import android .content .pm .PackageInfo ;
66import android .content .pm .PackageManager ;
7- import android .content .res .AssetManager ;
87import android .os .Build ;
98import android .os .Environment ;
109import android .util .Log ;
1110import com .facebook .react .ReactInstanceManager ;
12- import java .io .ByteArrayOutputStream ;
1311import java .io .File ;
14- import java .io .IOException ;
15- import java .io .InputStream ;
1612import java .util .concurrent .Executor ;
1713import java .util .concurrent .Executors ;
1814
@@ -39,9 +35,6 @@ public class UpdateContext {
3935 private static final int STATE_OP_CLEAR_ROLLBACK_MARK = 5 ;
4036 private static final int STATE_OP_RESOLVE_LAUNCH = 6 ;
4137 private static final String KEY_FIRST_LOAD_MARKED = "firstLoadMarked" ;
42- private static final String KEY_BUNDLE_HASH_CACHE_IDENTITY = "bundleHashCacheIdentity" ;
43- private static final String KEY_BUNDLE_HASH_CACHE_VALUE = "bundleHashCacheValue" ;
44- private static final String EMBEDDED_BUNDLE_ASSET_NAME = "index.android.bundle" ;
4538
4639 // Singleton instance
4740 private static UpdateContext sInstance ;
@@ -62,8 +55,6 @@ private static native StateCoreResult runStateCore(
6255 boolean flagB
6356 );
6457
65- private static native String hashBytes (byte [] data );
66-
6758 public UpdateContext (Context context ) {
6859 this .context = context .getApplicationContext ();
6960 this .executor = Executors .newSingleThreadExecutor ();
@@ -119,47 +110,6 @@ public boolean getIsUsingBundleUrl() {
119110 return isUsingBundleUrl ;
120111 }
121112
122- public String getBundleHash () {
123- String identity = "embedded:" + getPackageVersion () + ":" + getBuildTime ();
124- String cachedIdentity = sp .getString (KEY_BUNDLE_HASH_CACHE_IDENTITY , null );
125- String cachedValue = sp .getString (KEY_BUNDLE_HASH_CACHE_VALUE , null );
126- if (identity .equals (cachedIdentity ) && cachedValue != null && !cachedValue .isEmpty ()) {
127- return cachedValue ;
128- }
129-
130- String bundleHash = hashAsset (EMBEDDED_BUNDLE_ASSET_NAME );
131- if (bundleHash == null ) {
132- return "" ;
133- }
134-
135- SharedPreferences .Editor editor = sp .edit ();
136- editor .putString (KEY_BUNDLE_HASH_CACHE_IDENTITY , identity );
137- editor .putString (KEY_BUNDLE_HASH_CACHE_VALUE , bundleHash );
138- persistEditor (editor , "cache bundle hash" );
139- return bundleHash ;
140- }
141-
142- private String hashAsset (String assetName ) {
143- try (InputStream stream = context .getAssets ().open (assetName , AssetManager .ACCESS_STREAMING )) {
144- return hashInputStream (stream );
145- } catch (IOException e ) {
146- if (DEBUG ) {
147- Log .w (TAG , "Failed to hash asset bundle " + assetName , e );
148- }
149- return null ;
150- }
151- }
152-
153- private String hashInputStream (InputStream stream ) throws IOException {
154- ByteArrayOutputStream output = new ByteArrayOutputStream ();
155- byte [] buffer = new byte [8192 ];
156- int read ;
157- while ((read = stream .read (buffer )) != -1 ) {
158- output .write (buffer , 0 , read );
159- }
160- return hashBytes (output .toByteArray ());
161- }
162-
163113 private void enqueue (DownloadTaskParams params ) {
164114 executor .execute (new DownloadTask (context , params ));
165115 }
0 commit comments