[Nexus 5 Q&A, Help & Troubleshooting] PohKean:
I have had this issue for the past 4 days. After many attempts of trying to bang the phone a lil onto my hand (for where the power button is located at), sometimes the phone will boot fine, for as long as you do not click the power button again it won't act up.

(I am pretty sure I didn't drop my phone when I was napping in the car, it just started out of nowhere after I have been using lollipop 5.0 with franco kernel for like 2 months without any problem).

Same sypmtoms, bootloop (looked like the power button defective / boot IC on mobo defective), can't even stay on recovery/bootloader screen/system for longer than 5 sec.

Try these :

- spam click power button, until it is able to boot into system, you will have to keep clicking, for every click you either screen on/off you will realize Power Off options may pop up, it looks like the power button has been holded for few sec to trigger the power off, but all you do was spamming the click to keep the button active, you have to click until you feel that certain point the power off doesn't pop up, then stop clicking ( remember never to touch that power button again for NOW), if after a few sec of using the phone and it doesn't force shut down (result from power button defective where it sense its being clicked and hold for like 8-15 sec). Then you are good to carry on whatever I am to tell here.

- go to about phone, click the build number for 5-10 times until you get the unlocked developer mode

- back, click on developer options, enable usb debugging mode (this will pop another message asking you if you want the device to memorise your pc's mac address) that way it is synced with your pc.

- before you proceed with any other thing, go to playstore, download power button to volume button, enable volume power, check start volume power on bootup, check screen off. This will help you greatly for not touching the power button to unlock the screen when you are working on your pc.

- if you have all the correct nexus usb driver installed onto your pc, you need to get Minimal ADB and Fastboot installed onto pc. After installing, run Minimal adb and fastboot, a command prompt windows will pop out and is automatically redirected to the minimal adb folder. key in this command

"adb devices" to see if it detects your device or not. There should be at least a device listed if you have the usb driver installed correctly

- now you can make use of adb commands to reboot into bootloader/recovery to do any flashing of system, backup all your data that you needed to PC. Download official 5.0.1 nexus 5 image and extract it into the Minimal ADB folder.

- is your bootloader unlocked? if not do adb reboot-bootloader

- fastboot oem unlock (this will wipe all your data on the phone)

- fastboot reboot after the wipe is done

After that you can actually carry on with flashing back to stock images. Look at this link http://xdaforums.com/google-nexus-5/general/tutorial-how-to-flash-factory-image-t2513701 for flashing to stock factory image.

I am not sure which step has actually solved my problem, because on my first flashing of factory image, booting into system as a brand new device (no extra softwares, yet to recover any of my data). the problem persists as long as I clicked on power button once, it'll act up again random power off and bootloop.

I actually was on a follow-up cases with google play support team from Aus as my device was bought from Aus. After the last step of factory image setting, doesn't help, I intended to ship it back for RMA as my device is still under warranty and I suspected it was the hardware issues from power button too. They will send me another refurbished device. After ending the call, they sent me link to proceed with warranty claims where I need to fill in several forms and ship the device back to them.

I decided to give it one more try, due to my phone was previously unlocked, rooted, changed to franco kernel.

By restoring to stock images made my device unroot, I was afraid of google will accuse me for unlocking bootloader voided the warranty and not willing to replace another unit for me. I locked back the bootloader, then I remembered in bootloader, fastboot oem device-info shows that a record of a phone if it has been unlocked, it will show Tampered status as True, google probably can use that to track if a device has been unlocked before. So I unlocked my bootloader again (which causing another wipe for whatever data is in the device).

So I looked up on google again and found source for changing that tampered status to False in addition to locking the bootloader again, but to change that tampered status, I need to use TWRP to run the scripted zip file, so I used fastboot boot path (it is stated in the link I gave you above) to boot into TWRP images temporarily from my desktop and ran the zip file, I always practice wiping data, cache and everything before I boot the device back into a brand new factory image.

So I went to wipe dalvik cache. Rebooted the system - it was running the Optimizing x numbers of Applications.

Upon finished with that. I was surprised that, after a few clicks of power button, the random power off issues is no longer there. I even test clicking on the power button for entire day. The symptom isn't coming back. So I emailed google play support team to cancel my warranty ticket and close the case for now.

Should there be any problem again I will probably then claim the warranty for replacement.

Its been more than 24 hours now that I am using the device without any problem of random power off and on or stuck in bootloop due to power button defective.

I suspect it is either the 5.01/5.0 lollipop with ART that is causing something wrong with the boot IC / power button defective in a long run.

Or maybe it was some settings I have changed in franco kernel ? but it was running fine for 2 months which made me doubt that it is franco kernel

Or it could be some of the apps I used to tweak my phone settings - LLama and tactile player (which I have set something condition and actions for power button) but I doubt it is caused by these either.

I will observe and see if the problem comes back after some time of using the 5.0.1 stock image now.

Oh I am also back to using franco kernel, unlocked bootloader and rooted again. Haha...

Hopefully you are able to solve the problem by trying some factory reset method + wiping cache, partition and dalvik.

If not, you probably may have the hardware issues, I have seen some other forum/websites with n5 users upon replacing the mobo, no longer encounter such problem.

Regards,

Kean