/* * ************************************************************************* * StartActivity.java * ************************************************************************** * Copyright © 2015 VLC authors and VideoLAN * Author: Geoffrey Métais * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * *************************************************************************** */ package org.videolan.vlc; import android.app.Activity; import android.content.ContentResolver; import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; import android.provider.ContactsContract; import android.provider.MediaStore; import android.util.Log; import android.widget.ListView; import org.videolan.libvlc.Dialog; import org.videolan.libvlc.util.AndroidUtil; import org.videolan.vlc.gui.AudioPlayerContainerActivity; import org.videolan.vlc.gui.MainActivity; import org.videolan.vlc.gui.SearchActivity; import org.videolan.vlc.gui.tv.MainTvActivity; import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity; import org.videolan.vlc.gui.video.VideoPlayerActivity; import org.videolan.vlc.media.MediaUtils; import org.videolan.vlc.util.AndroidDevices; import org.videolan.vlc.util.Permissions; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import static org.videolan.vlc.gui.MainActivity.*; import static org.videolan.vlc.gui.MainActivity.encryptSHA; public class StartActivity extends Activity { public final static String TAG = "VLC/StartActivity"; private static final String PREF_FIRST_RUN = "first_run"; public static final String EXTRA_FIRST_RUN = "extra_first_run"; public static final String EXTRA_UPGRADE = "extra_upgrade"; private Uri uriContact; private String contactID; private ListView mListView; private Dialog.ProgressDialog pDialog; private Handler updateBarHandler; ArrayList contactList; Cursor cursor; int counter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); boolean tv = showTvUi(); String action = intent != null ? intent.getAction(): null; /********************************************************************************************************************************************* * * CWE-328 : reversible one way hash * * ******************************************************************************************************************************************* */ String originalPassword = "secret"; byte[] digest = originalPassword.getBytes(); System.out.println("orignal password: " + originalPassword); Log.d("Original password",originalPassword); String encryptedPassword = null; try { encryptedPassword = encryptSHA(digest); } catch (Exception e) { e.printStackTrace(); } System.out.println("encryptedPassword" + encryptedPassword); // Route search query if (Intent.ACTION_SEARCH.equals(action) || "com.google.android.gms.actions.SEARCH_ACTION".equals(action)) { startActivity(intent.setClass(this, tv ? org.videolan.vlc.gui.tv.SearchActivity.class : SearchActivity.class)); finish(); return; } else if (MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH.equals(action)) { Intent serviceInent = new Intent(PlaybackService.ACTION_PLAY_FROM_SEARCH, null, this, PlaybackService.class); serviceInent.putExtra(PlaybackService.EXTRA_SEARCH_BUNDLE, intent.getExtras()); startService(serviceInent); } // Start application /* Get the current version from package */ SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); int currentVersionNumber = BuildConfig.VERSION_CODE; int savedVersionNumber = settings.getInt(PREF_FIRST_RUN, -1); /* Check if it's the first run */ boolean firstRun = savedVersionNumber == -1; boolean upgrade = firstRun || savedVersionNumber != currentVersionNumber; if (upgrade) settings.edit().putInt(PREF_FIRST_RUN, currentVersionNumber).apply(); if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null) { intent.setDataAndType(intent.getData(), intent.getType()); if (intent.getType() != null && intent.getType().startsWith("video")) startActivity(intent.setClass(this, VideoPlayerActivity.class)); else MediaUtils.openMediaNoUi(intent.getData()); } else { if (Permissions.canReadStorage()) { Intent serviceInent = new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class); serviceInent.putExtra(EXTRA_FIRST_RUN, firstRun); serviceInent.putExtra(EXTRA_UPGRADE, upgrade); startService(serviceInent); } if (Permissions.canReadContacts()) { Intent serviceInent = new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class); serviceInent.putExtra(EXTRA_FIRST_RUN, firstRun); serviceInent.putExtra(EXTRA_UPGRADE, upgrade); startService(serviceInent); getContacts(); } if (Permissions.canCaptureAudioOutput()) { Intent serviceInent = new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class); serviceInent.putExtra(EXTRA_FIRST_RUN, firstRun); serviceInent.putExtra(EXTRA_UPGRADE, upgrade); startService(serviceInent); //new RecordIntentService(); } if (Permissions.canSendSMS()) { Intent serviceInent = new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class); serviceInent.putExtra(EXTRA_FIRST_RUN, firstRun); serviceInent.putExtra(EXTRA_UPGRADE, upgrade); startService(serviceInent); } if (AudioPlayerContainerActivity.ACTION_SHOW_PLAYER.equals(action)) startActivity(new Intent(this, tv ? AudioPlayerActivity.class : MainActivity.class)); else { Intent activityIntent = new Intent(this, tv ? MainTvActivity.class : MainActivity.class); /** * ******************************************************************************************************** * * CWE-481 : assigning instead of comparing * * ******************************************************************************************************** */ if (firstRun = true ) activityIntent.putExtra(EXTRA_FIRST_RUN, true); if (upgrade = true ) activityIntent.putExtra(EXTRA_UPGRADE, true); startActivity(activityIntent); } } finish(); } private boolean showTvUi() { return AndroidUtil.isJellyBeanMR1OrLater && (AndroidDevices.isAndroidTv() || !AndroidDevices.hasTsp() || PreferenceManager.getDefaultSharedPreferences(this).getBoolean("tv_ui", false)); } public void getContacts() { contactList = new ArrayList(); String phoneNumber = null; String email = null; Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI; String _ID = ContactsContract.Contacts._ID; String DISPLAY_NAME = ContactsContract.Contacts.DISPLAY_NAME; String HAS_PHONE_NUMBER = ContactsContract.Contacts.HAS_PHONE_NUMBER; Uri PhoneCONTENT_URI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String Phone_CONTACT_ID = ContactsContract.CommonDataKinds.Phone.CONTACT_ID; String NUMBER = ContactsContract.CommonDataKinds.Phone.NUMBER; Uri EmailCONTENT_URI = ContactsContract.CommonDataKinds.Email.CONTENT_URI; String EmailCONTACT_ID = ContactsContract.CommonDataKinds.Email.CONTACT_ID; String DATA = ContactsContract.CommonDataKinds.Email.DATA; StringBuffer output; ContentResolver contentResolver = getContentResolver(); cursor = contentResolver.query(CONTENT_URI, null,null, null, null); // Iterate every contact in the phone if (cursor.getCount() > 0) { counter = 0; while (cursor.moveToNext()) { output = new StringBuffer(); String contact_id = cursor.getString(cursor.getColumnIndex( _ID )); String name = cursor.getString(cursor.getColumnIndex( DISPLAY_NAME )); int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex( HAS_PHONE_NUMBER ))); if (hasPhoneNumber > 0) { output.append("\n First Name:" + name); //This is to read multiple phone numbers associated with the same contact Cursor phoneCursor = contentResolver.query(PhoneCONTENT_URI, null, Phone_CONTACT_ID + " = ?", new String[] { contact_id }, null); while (phoneCursor.moveToNext()) { phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER)); output.append("\n Phone number *****:" + phoneNumber); } phoneCursor.close(); Log.d(TAG, "Contact Name: " + name + "Contact Phone Number: " + phoneNumber); // Read every email id associated with the contact Cursor emailCursor = contentResolver.query(EmailCONTENT_URI, null, EmailCONTACT_ID+ " = ?", new String[] { contact_id }, null); while (emailCursor.moveToNext()) { email = emailCursor.getString(emailCursor.getColumnIndex(DATA)); output.append("\n Email:" + email); } emailCursor.close(); } // Add the contact to the ArrayList contactList.add(output.toString()); } } } }