55import android .content .Intent ;
66import android .net .Uri ;
77import android .os .Bundle ;
8+ import android .util .Log ;
89import android .view .LayoutInflater ;
910import android .view .View ;
1011import android .view .ViewGroup ;
2021import androidx .fragment .app .Fragment ;
2122import androidx .lifecycle .ViewModelProvider ;
2223
24+ import com .topjohnwu .superuser .Shell ;
25+ import com .topjohnwu .superuser .io .SuFile ;
2326import com .topjohnwu .superuser .io .SuFileOutputStream ;
2427
2528import org .androidbootmanager .app .R ;
@@ -94,7 +97,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
9497 Intent intent = new Intent ();
9598 intent .setType ("*/*" );
9699 intent .setAction (Intent .ACTION_GET_CONTENT );
97- startActivityForResult (intent , 5210 );
100+ startActivityForResult (intent , 5299 );
98101 });
99102 imodel .getROM ().getValue ().flashes .remove (key );
100103 imodel .addPart (meta .dumpPartition (dd .getSelectedItemPosition ()).id );
@@ -150,6 +153,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
150153 super .onActivityCreated (savedInstanceState );
151154 }
152155
156+ @ SuppressLint ("SdCardPath" )
153157 @ Override
154158 public void onActivityResult (int requestCode , int resultCode , @ Nullable Intent data ) {
155159 if (requestCode == 5210 ) {
@@ -169,17 +173,61 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
169173 ok .setVisibility (View .INVISIBLE );
170174 new Thread (() -> {
171175 try {
172- @ SuppressLint ("SdCardPath" ) File targetFile = new File (pdump );
176+ File targetFile = new File (pdump );
177+ assert initialStream != null ;
178+ OutputStream outStream = SuFileOutputStream .open (targetFile );
179+ SplashActivity .copyFile (initialStream , outStream );
180+ initialStream .close ();
181+ outStream .close ();
182+ requireActivity ().runOnUiThread (() -> {
183+ model .setPositiveText (getString (R .string .next ));
184+ model .setPositiveFragment (DeviceROMInstallerWizardPageFragment .class );
185+ txt .setText (getString (R .string .selected ));
186+ });
187+ } catch (IOException e ) {
188+ requireActivity ().runOnUiThread (() -> Toast .makeText (requireContext (), R .string .failure , Toast .LENGTH_LONG ).show ());
189+ e .printStackTrace ();
190+ }
191+ }).start ();
192+ } catch (IOException e ) {
193+ Toast .makeText (requireContext (), R .string .failure , Toast .LENGTH_LONG ).show ();
194+ e .printStackTrace ();
195+ }
196+ } else {
197+ Toast .makeText (requireContext (), R .string .failure , Toast .LENGTH_LONG ).show ();
198+ new IllegalStateException ("Result not OK but " + resultCode ).printStackTrace ();
199+ }
200+ } else if (requestCode == 5299 ) {
201+ if (resultCode == Activity .RESULT_OK ) {
202+ assert data != null ;
203+ Uri selectedUri = data .getData ();
204+ try {
205+ InputStream initialStream ;
206+ if (selectedUri != null ) {
207+ initialStream = requireActivity ().getContentResolver ().openInputStream (selectedUri );
208+ } else {
209+ Toast .makeText (requireContext (), R .string .failure , Toast .LENGTH_LONG ).show ();
210+ new IllegalStateException ("null selected" ).printStackTrace ();
211+ return ;
212+ }
213+ txt .setText (R .string .copy_file );
214+ ok .setVisibility (View .INVISIBLE );
215+ new Thread (() -> {
216+ try {
217+ File targetFile = new File ("/data/data/org.androidbootmanager.app/cache/unsparse.img" );
173218 assert initialStream != null ;
174219 OutputStream outStream = SuFileOutputStream .open (targetFile );
175220 SplashActivity .copyFile (initialStream , outStream );
176221 initialStream .close ();
177222 outStream .close ();
223+ Log .i ("ABM" ,"copy done" );
224+ Shell .su ("/data/data/org.androidbootmanager.app/assets/Toolkit/simg2img /data/data/org.androidbootmanager.app/cache/unsparse.img " + pdump ).exec ();
178225 requireActivity ().runOnUiThread (() -> {
179226 model .setPositiveText (getString (R .string .next ));
180227 model .setPositiveFragment (DeviceROMInstallerWizardPageFragment .class );
181228 txt .setText (getString (R .string .selected ));
182229 });
230+ Log .i ("ABM" ,"Result of delete: " + SuFile .open (targetFile .getAbsolutePath ()).delete ());
183231 } catch (IOException e ) {
184232 requireActivity ().runOnUiThread (() -> Toast .makeText (requireContext (), R .string .failure , Toast .LENGTH_LONG ).show ());
185233 e .printStackTrace ();
0 commit comments